Closed (outdated)
Project:
Link
Version:
7.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
17 Jan 2016 at 19:06 UTC
Updated:
5 Sep 2020 at 14:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
laborouge commentedSame bug for me, with and without Advanced Link Module as the widget.
Path are not supported, just full URLs or node/nid.
Subscribe.
Comment #3
ijhaas commentedTrying to save a link with a relative path gives: 'the value "content/xxx/xxx"is not a valid URL
Comment #4
jasonschweb commentedI've found that the function link_validate_url($text, $langcode = NULL) seems to only validate if the language isn't provided / NULL. I just commented out $langcode from the function call on line 423 which got it working again. This is certainly not an ideal solution, and would probably break on a multi-lingual site.
if (!link_validate_url(trim($item['url'])/*, $langcode*/)) {
Comment #5
jasonschweb commentedIn addition to the above, it's also validating on unpublish, so URLs that had been entered before the validation change in 1.4 that where working are unable to be unpublished without editing the URL.
Comment #6
jurgenhaasStarting with version 1.4 this is also broken for multilingual sites with a language prefix.
In version 1.4 the language prefix appears twice. Haven't found the reason yet but this can be reproduced in theme_link_formatter_link_default() where in $vars['element']['url'] in version 1.3 we get the canonical URL but in 1.4 we get the alias which already contains the language prefix. And then the theme function calls url() again which is adding the same language prefix again.
Comment #7
znerol commentedI can reproduce #4,
link_validate_urlfails to validate an alias if$language != NULL. The affected link field is inside a field collection.I guess this problem might occur if the host entity (i.e. the node containing the link field) has a different language than the page an url alias points at. I'm not quite sure whether it is correct to pass the langcode of the host entity when looking up an alias.
My current workaround (attached patch) is to simply try and resolve the alias without a langcode set if the original code fails. Please do not use this patch in production. It just demonstrates the problem and is likely not the proper solution for it.
Comment #8
Rkhatun commentedI have fixed the problem with using relative path in link field in Drupal 7. At current, the validation for link module does not validate if it is not absolute URL therefore this patch applies feature check both system and path alias for a given path.
Comment #10
jurgenhaasThis patch doesn't solve the problem of duplicate language prefixes mentioned in #6
Comment #11
Rkhatun commentedFix formatting issues in #8 and this patch only to fix problem with relative url only.
Comment #12
vchen commentedJust tried patch#11 and that seemed to have fixed the problem for me with the relative url. Thanks!
Comment #13
jcfiala commented#11 looks good, but it seems to have failed the test on validating rss.xml.
Comment #14
off commentedSame problem in 1.4 version:
The value calc provided for Link is not a valid URL.
Just download version 1.3 and problem is gone..
Comment #15
jrglasgow commentedComment #18
jsst commentedPatch #8 and #11 replace the call to drupal_valid_path() with drupal_lookup_path('alias', ..) but those are not the same, hence the failing test case. I've attached a new patch which uses drupal_lookup_path('source', ...) in addition to the unchanged existing behaviour. This should fix the reported issue and the failing test case.
Comment #19
jsst commentedComment #20
jsst commentedSame as #18 but return value is now always a boolean value.
Comment #21
jrglasgow commentedI have a client having this problem as well. In my research I found that the issue is with the language settings. Node translation is on and the default language is English.
When the url aliases are being generated they use the node language as a key.
_field_invoke('validate')creates a list of available languages and passes a "language suggestion" on the thelink_field_validate()function. The available languages it uses are valid languages for the field, assuming that the field is translatable. Otherwise it uses theLANGUAGE_NONEvalue of 'und'. Whenlink_validate_url()gets the information to validate the url it receives the field language only, not the node language.I believe it should not only check against the field language passed to it but also check against the language of the node the field is attached to. The attached patch will check against the node language is the check against the field language fails.
Comment #22
jsst commentedHi jrglasgow,
do you use your patch in conjunction with one of the previous patches in this issue? If so, we should produce one unified patch. If not, perhaps you're dealing with a different bug and it might be better to create a separate issue for it.
Comment #23
victoriachan commentedHi,
Just want to add that I have tried the patches from #11 and #21 separately on a client's site with this problem, and neither worked for internal links. Languages is not enabled, so it's probably not due to the language issue that some have stated here.
We didn't want to spend to much time on this, so we have merely reverted back to 1.3 where it was working, and didn't investigate further.
Thanks,
Victoria
Comment #24
znerol commented@victoriachan This also happens on single language sites if there is a specific language set for some fields/entities and none (LANGUAGE_NONE) for others.
Comment #25
nickvanboven commentedHi,
Just want to add that i have the same problem but i am using link inside inline entity form. v1.3 working perfect v1.4 giving problems
Comment #26
softone commentedI can confirm that #20 fixes this issue with internal links when working with advanced link module on multilingual site.
Comment #27
karimei commentedFor me too #20 fixes the issue. I'm using Link as widget.
Prior to applying the patch internal links that have been entered as URL aliases were not accepted as valid URL.
Comment #28
nitebreed#21 works for me!
Comment #29
renrhaf#21 works for me too.
More context:
- It's on a site using a Link field with an Advanced Link widget
- On a node with translation enabled using "field translation" from entity_translation module.
- The link field having translation disabled.
This lead to the call of `link_validate_url` with `LANGUAGE_NONE` langcode and thus the function `drupal_get_normal_path` can't find the right internal path to this content, and validation fails. The workaround from #21 works because we try again with the node's language and then internal path can be found.
(issue seems to be linked with https://www.drupal.org/node/2632728)
Comment #30
mathieuhelie commentedIf none of the fixes here work for you, a patch that reverts the new validation layer can be found in #2666912: URL validation rejects existing valid content after upgrade to 7.x-1.4.
Comment #31
jasonschweb commentedHow about a separate configuration option for strict validation of links? The default validation could just GET the url and check that it returns a 200, and strict could confirm it's a valid Drupal route or public file. In most situations, "check that it returns a 200" should be good enough, but this would let people configure what will work best for their site.
It could also be a three-way selection for "validate URL format only / validate URL / validate that URL matches a drupal route"
Comment #32
eyilmazThere is one use case, which is not covered with #21.
Applying the patch in #21 means that users can only link internal links with the same language.
As an example:
- We have a node with language "en"
- We have another entity with language "und" and field_link, also without language: so also "und".
This would mean, that we are not able to link the node with the language "en" via the field_link in the mentioned entity with language "und".
Does it make any sense to restrict the language of the linked url?
I mean, why shouldn't people be able to link an english content from content with none language?
If this has a reason, this should be configurable.
For now, I would say, let's remove the $langcode in the function call to link_validate_url in _link_validate.
As mentioned in #4
Patch is attached.
Comment #34
jose.cely commented#21 works for me too.
I have Drupal 7.44 and Link module 7.x-1.4
Thanks a lot
Comment #35
peximo commentedI think it's necessary to verify that the URL is valid at least in one of the languages of the website. So in my opinion we don't need to check the field or the entity language but all the languages enabled in the site.
Patch is attached.
Comment #36
jelle_sComment #38
jelle_s? The test fails seem unrelated to the patch. The tests fail to create a new field through the UI.
Comment #40
jsst commentedI've tested the #35 patch with internal links with and without inline entity form. Those use-cases seem covered now, works well. Can't vouch for multilingual sites. But these things should really be covered by tests. I'm not sure if we should proceed in this direction in the next version of this module. Simply reverting the feature (https://www.drupal.org/node/2666912) seems a lot safer.
Comment #41
jelle_sFWIW: I've tested patch #35 on multilingual sites, validation that failed at first passes with the patch (alias existed but for a different language than the field/entity language).
Comment #42
jsst commentedThat makes it RTBC. I guess it's up to a maintainer to merge either this one or https://www.drupal.org/node/2666912.
Comment #43
cozzamara commentedAlso the same issue for me. I'm not tried any patch, and I wait an release updating. Please fix soon.
Comment #45
yonailo#20 + #21 work for me, I think those combined are the right fix for this issue.
Comment #46
gaurav.kapoor commentedThis should fix it.
Comment #48
michael_wojcik commentedNew patch combines the multilingual support offered by #35 with the patch from #46, which had combined #20 and #21. This new patch also revises the order in which URLs are currently parsed with link_validate_url(), and thereby fixes the issue with valid relative URL paths that happen to contain query strings as well. URL aliases are now parsed first, before being passed to drupal_get_normal_path(), which cannot handle alias that contain query params, etc. See https://www.drupal.org/node/2861356 for further explanation/diagnosis. Interdiff files included to show difference between #35 and #48 and between #46 and #48.
Comment #50
Anonymous (not verified) commentedPatch #48 works very nicely for one client site. (Now to patch all the sites that use this module.)
This seems like the best solution to the issues introduced by the change in validation in 7.x-1.5.
Thanks!
Comment #51
sachbearbeiter commentedAnd in general: Don't use Drupal 7 anymore! Update to Drupal 8 or change to Wordpress f.e.
Comment #52
komejo commentedFor anyone coming here after updating from 1.3 (due to the security update), and seeing the same issue as #6, this patch works: 'Language prefix and relative links broken': https://www.drupal.org/node/2428185
Comment #53
damienmckennaThis needs tests to make sure nothing else breaks.
Comment #54
cboyden commentedThe fix in #2428185: Language prefix and relative links broken (referenced in comment #52) has been committed and released in version 1.7. Does that resolve the problems identified in this issue?
Comment #55
damienmckennaIs this still a problem after #836710: Convert links to their internal link representation if they exist was committed?
Comment #56
olafski@cboyden, just tested: For me, the update to Link 1.7 fixed the issue on a site with relative paths in the link field.
Comment #57
damienmckennaPlease let us know if this problem still happens with the current release and we can reopen it, otherwise we're going to assume the problem has been fixed. Thank you.