Hi,
I use Link Module with Advanced Link Module as the widget.

I ticked Internal Link only & Validate URL.

I entered some words, auto-complete displayed related nodes (aliased path) and I clicked to confirm. When I saved, always showed "Not A Valid URL?" Why ? feature

To circumvent it, I entered node/2 , node/3 , node/4 instead of the aliased path shown in the auto-complete.

Thanks

Comments

paulwdru created an issue. See original summary.

laborouge’s picture

Same bug for me, with and without Advanced Link Module as the widget.

Path are not supported, just full URLs or node/nid.

Subscribe.

ijhaas’s picture

Trying to save a link with a relative path gives: 'the value "content/xxx/xxx"is not a valid URL

jasonschweb’s picture

I'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*/)) {

jasonschweb’s picture

In 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.

jurgenhaas’s picture

Starting 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.

znerol’s picture

StatusFileSize
new612 bytes

I can reproduce #4, link_validate_url fails 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.

Rkhatun’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new532 bytes

I 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.

Status: Needs review » Needs work

The last submitted patch, 8: fix_for_link_relative_not_valid_url-2651742-8.patch, failed testing.

jurgenhaas’s picture

This patch doesn't solve the problem of duplicate language prefixes mentioned in #6

Rkhatun’s picture

Fix formatting issues in #8 and this patch only to fix problem with relative url only.

vchen’s picture

Just tried patch#11 and that seemed to have fixed the problem for me with the relative url. Thanks!

jcfiala’s picture

#11 looks good, but it seems to have failed the test on validating rss.xml.

off’s picture

Same 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..

jrglasgow’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 11: fix_for_link_relative_not_valid_url-2651742-11.patch, failed testing.

The last submitted patch, 8: fix_for_link_relative_not_valid_url-2651742-8.patch, failed testing.

jsst’s picture

Patch #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.

jsst’s picture

Status: Needs work » Needs review
jsst’s picture

Same as #18 but return value is now always a boolean value.

jrglasgow’s picture

I 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 the link_field_validate() function. The available languages it uses are valid languages for the field, assuming that the field is translatable. Otherwise it uses the LANGUAGE_NONE value of 'und'. When link_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.

jsst’s picture

Hi 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.

victoriachan’s picture

Hi,

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

znerol’s picture

@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.

nickvanboven’s picture

Hi,

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

softone’s picture

I can confirm that #20 fixes this issue with internal links when working with advanced link module on multilingual site.

karimei’s picture

For 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.

nitebreed’s picture

#21 works for me!

renrhaf’s picture

#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)

mathieuhelie’s picture

If 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.

jasonschweb’s picture

How 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"

eyilmaz’s picture

StatusFileSize
new811 bytes

There 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.

Status: Needs review » Needs work

The last submitted patch, 32: link-always_not_a_valid_url-2651742-32.patch, failed testing.

jose.cely’s picture

#21 works for me too.
I have Drupal 7.44 and Link module 7.x-1.4

Thanks a lot

peximo’s picture

StatusFileSize
new1018 bytes

I 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.

jelle_s’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 35: link-always_not_a_valid_url-2651742-35.patch, failed testing.

jelle_s’s picture

Status: Needs work » Needs review

? The test fails seem unrelated to the patch. The tests fail to create a new field through the UI.

Status: Needs review » Needs work

The last submitted patch, 35: link-always_not_a_valid_url-2651742-35.patch, failed testing.

jsst’s picture

I'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.

jelle_s’s picture

FWIW: 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).

jsst’s picture

Status: Needs work » Reviewed & tested by the community

That makes it RTBC. I guess it's up to a maintainer to merge either this one or https://www.drupal.org/node/2666912.

cozzamara’s picture

Also the same issue for me. I'm not tried any patch, and I wait an release updating. Please fix soon.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 35: link-always_not_a_valid_url-2651742-35.patch, failed testing.

yonailo’s picture

#20 + #21 work for me, I think those combined are the right fix for this issue.

gaurav.kapoor’s picture

Status: Needs work » Needs review
StatusFileSize
new1.17 KB

This should fix it.

Status: Needs review » Needs work

The last submitted patch, 46: link-always-not-a-valid-url-2651742-46.patch, failed testing.

michael_wojcik’s picture

Status: Needs work » Needs review
StatusFileSize
new1.67 KB
new1.48 KB
new937 bytes

New 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.

Status: Needs review » Needs work

The last submitted patch, 48: link-always-not-a-valid-url-2651742-48.patch, failed testing.

Anonymous’s picture

Patch #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!

sachbearbeiter’s picture

And in general: Don't use Drupal 7 anymore! Update to Drupal 8 or change to Wordpress f.e.

komejo’s picture

For 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

damienmckenna’s picture

Version: 7.x-1.4 » 7.x-1.x-dev
Issue tags: +Needs tests

This needs tests to make sure nothing else breaks.

cboyden’s picture

The 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?

damienmckenna’s picture

olafski’s picture

@cboyden, just tested: For me, the update to Link 1.7 fixed the issue on a site with relative paths in the link field.

damienmckenna’s picture

Status: Needs work » Closed (outdated)

Please 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.