Problem/Motivation

Take a look at how commerce_product_validate_sku() is written:

function commerce_product_validate_sku($sku) {
  // Do not allow commas in a SKU.
  if (strpos($sku, ',')) {
    return FALSE;
  }

  return TRUE;
}

With it being written this way if $sku starts with a comma it will give a false positive.

For example:

$invalidSku = ',sku';
$anotherInvalidSku = ',,,,,,';

if(commerce_product_validate_sku($invalidSku) {
  echo $invalidSku . " is valid";
}
else {
  echo $invalidSku . " is invalid";
}

if(commerce_product_validate_sku($anotherInvalidSku) {
  echo $anotherInvalidSku . " is valid";
}
else {
  echo $anotherInvalidSku . " is invalid";
}

Output:

,sku is valid
,,,,,, is valid

Clearly this shouldn't be happening.

Proposed resolution

Change the implementation of commerce_product_validate_sku() so that it will not return any false positives.

CommentFileSizeAuthor
#1 2510344-1.patch485 bytescbanman

Comments

cbanman’s picture

StatusFileSize
new485 bytes

Here is my suggested fix. It's a simple fix that will ensure no false positives.

rszrama’s picture

Status: Active » Fixed

Nice find, and thanks for the patch! Happy to see a commit from an Acro dev after meeting Becky in LA. : )

  • rszrama committed eadf94d on 7.x-1.x authored by cbanman
    Issue #2510344: fix the logic check to prevent commas from being added...

Status: Fixed » Closed (fixed)

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