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.
Comments
Comment #1
cbanman commentedHere is my suggested fix. It's a simple fix that will ensure no false positives.
Comment #2
rszrama commentedNice find, and thanks for the patch! Happy to see a commit from an Acro dev after meeting Becky in LA. : )