On posting a new node I'm getting this message:-

Notice: Undefined index: validate_url in link_field() (line 229 of /srv/bindings/ab331aab8e404f6d89add5010badaee5/code/sites/all/modules/link/link.module).

I tried to make this change to guard against nonexistent array indices, but the message still exists.

-      if ($field['validate_url'] !== 0 || is_null($field['validate_url']) || !isset($field['validate_url'])) {
+      if (array_key_exists('validate_url', $field) || $field['validate_url'] !== 0 || is_null($field['validate_url']) || !isset($field['validate_url'])) {

Comments

reikiman’s picture

Ah.. I had the test wrong. This makes the message go away:-

if (!array_key_exists('validate_url', $field) || ...

reikiman’s picture

I found another instance where the fix is:-

diff --git a/sites/all/modules/link/link.module b/sites/all/modules/link/link.module
index 60ca2cc..a7d888b 100644
--- a/sites/all/modules/link/link.module
+++ b/sites/all/modules/link/link.module
@@ -373,7 +373,7 @@ function _link_sanitize(&$item, $delta, &$field, &$node) {
     $url = substr($url, 0, strpos($url, '?'));
   }
   // Save the new URL without the anchor or query.
-  if ($field['validate_url'] === 0) {
+  if (array_key_exists('validate_url', $field) && $field['validate_url'] === 0) {
     $item['url'] = check_plain($url);
   }
   else {
damienmckenna’s picture

Version: 6.x-2.9 » 6.x-2.x-dev
Status: Active » Needs review
StatusFileSize
new945 bytes

This will fix the error in the D6 -dev version for both lines 85 and 101.

damienmckenna’s picture

StatusFileSize
new961 bytes

This fixes the problem in 6.x-2.9.

brad.bulger’s picture

StatusFileSize
new2.04 KB

reroll against current 2.x-dev code, including a few additional changes (eg is_null() and !isset() are equivalent)

could this get applied? it's been almost a year. thanks.

yhager’s picture

+      if (!isset($field['validate_url']) || $field['validate_url'] !== 0) {

this looks backwards to me - if validate_url is not set we should not validate the url.

brad.bulger’s picture

compare it to the original code:

-      if ($field['validate_url'] !== 0 || is_null($field['validate_url']) || !isset($field['validate_url'])) {

i guess the idea was that if it doesn't explicitly have a value of zero, then the validation should happen?

yhager’s picture

Yeah, I know it is like the original code, but it still does not make sense to me :) (or at least looks very hacky)

brad.bulger’s picture

Issue summary: View changes

well can i suggest that that's a separate issue? the point here is to fix the undefined index notice, not to rewrite the module logic. that may also be a thing worth doing, but for its own sake. meanwhile, this is a solution to a problem that has existed for over a year.

jcfiala’s picture

Status: Needs review » Reviewed & tested by the community

I'll pour this in the next time I'm working on 6.x.

jcfiala’s picture

Status: Reviewed & tested by the community » Fixed

Okay, this has been committed - should show up in 6.x-2.x-dev by tomorrow, I expect. If folks could give it a quick look sometime soon and comment if there's a problem, that would be a help.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

yhager’s picture

Status: Closed (fixed) » Reviewed & tested by the community

Looks like this was not committed yet.

yhager’s picture

Status: Reviewed & tested by the community » Fixed

Sorry, my bad, it's in commit 6d9890b5

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jenlampton’s picture

looks like this never got into an official release for 6.x. Patch in #5 applies to latest stable with some offset.