Steps to reproduce;

  1. Install a version of Link module 7.x-1.x-dev recent enough to include this patch from comment 14 at #1321482. I actually used 7.x-1.0 with that patch applied.
  2. Configure the site such that certain types of node updates occur twice in one request. I have not narrowed down exactly which types of node-updates. For the purpose of this issue and patch I don't think it matters. This configuration reproduced the bug for me;
    1. Install Workbench Moderation and Rules modules.
    2. Create a Rule that is triggered by moderation transition;
      • Add a condition, such as that the "Sticky" flag must be set. This will make testing easier.
      • The Rule's actions should automatically publish content. That means it sets the moderation state to published.
  3. Configure a content type with a Link-module link-field.
  4. Create content with URLs that include fragments and/or query string parameters.
  5. Transition the content's moderation state such that the Rule does not trigger, so that only one moderation transition occurs in the request that is handled by form submission.
  6. Note that the URL in the rendered link field is the URL that was entered into the node edit form. Awesome!
  7. Now set the content's state such that the Rule does trigger, so that two moderation transitions occur in the request that is handled by form submission.
    • Expected behaviour: The URL in the rendered link field matches what was previously entered into the node form.
    • Actual behaviour: The fragment appears twice in the URL. I am not sure why this does only happens to fragments and not query strings.
  8. Create a new draft from the published content. AKA, edit the node.
    • Expected behaviour: The URL in the link field of the node form matches what was previously entered into the node form.
    • Actual behaviour: The fragment and query are duplicated in the URL in the link field of the node form.

This patch fixes the issue by unsetting $item['fragment'] and $item['query'] in _link_process() so that subsequent calls to the link_field_presave() (_link_process()'s only caller) in the same request don't append the fragment or query to the URL again.

I am not sure if this breaks other things.

Comments

Bevan’s picture

StatusFileSize
new533 bytes

This patch is identical but has no offset against 7.x-1.x-dev.

zach harkey’s picture

StatusFileSize
new697 bytes

Your code works but it assumes the existence of another patch from #1321482: Query string and fragment are removed and it looks like that issue was closed without ever committing the necessary lines.

Here is a new patch that should apply cleanly to 7.x-1.x

rreiss’s picture

I had the same issue on Link 7.x-1.0.
Links with query params. was printed twice, I guess that once because of the query saved with the URL and second because of the query params. sanitation performed on function `_link_sanitize`.

The patch here didn't work for me, due to different structure of the involved arrays, but the link from https://www.drupal.org/node/1984398#comment-7365328 did work.

Thanks.

jcfiala’s picture

Is anyone still having this problem with Link 7.x-1.3?

Is there a way to reproduce this which is less complex?

jcfiala’s picture

Status: Needs review » Postponed (maintainer needs more info)

I repeat myself, as I'm changing the status:

Is anyone still having this problem with Link 7.x-1.3?

Is there a way to reproduce this which is less complex?