Skip to content

Commit b3f3407

Browse files
committed
Pass delimiter char to preg_quote
The most common used delimiters in PHP are /@#~, which are not escaped by default (by default preg_quote escapes .\+*?[^]$(){}=!<>|:-).
1 parent f19c4af commit b3f3407

File tree

8 files changed

+14
-14
lines changed

8 files changed

+14
-14
lines changed

app/code/core/Mage/Api2/Model/Resource/Validator/Eav.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ public function getErrors()
225225
// business asked to avoid additional validation message, so we filter it here
226226
$errors = array();
227227
$requiredAttrs = array();
228-
$isRequiredRE = '/^' . str_replace('%s', '(.+)', preg_quote(Mage::helper('eav')->__('"%s" is a required value.'))) . '$/';
228+
$isRequiredRE = '/^' . str_replace('%s', '(.+)', preg_quote(Mage::helper('eav')->__('"%s" is a required value.')), '/') . '$/';
229229
$greaterThanRE = '/^' . str_replace(
230230
'%s',
231231
'(.+)',
232-
preg_quote(Mage::helper('eav')->__('"%s" length must be equal or greater than %s characters.'))
232+
preg_quote(Mage::helper('eav')->__('"%s" length must be equal or greater than %s characters.'), '/')
233233
) . '$/';
234234

235235
// find all required attributes labels

app/code/core/Mage/Catalog/Model/Url.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,8 @@ public function getUnusedPathByUrlKey($storeId, $requestPath, $idPath, $urlKey)
659659
}
660660
// match request_url abcdef1234(-12)(.html) pattern
661661
$match = array();
662-
$regularExpression = '#(?P<prefix>(.*/)?' . preg_quote($urlKey) . ')(-(?P<increment>[0-9]+))?(?P<suffix>'
663-
. preg_quote($suffix) . ')?$#i';
662+
$regularExpression = '#(?P<prefix>(.*/)?' . preg_quote($urlKey, '#') . ')(-(?P<increment>[0-9]+))?(?P<suffix>'
663+
. preg_quote($suffix, '#') . ')?$#i';
664664
if (!preg_match($regularExpression, $requestPath, $match)) {
665665
return $this->getUnusedPathByUrlKey($storeId, '-', $idPath, $urlKey);
666666
}

app/code/core/Mage/Core/Model/Translate/Inline.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ protected function _prepareTagAttributesForContent(&$content)
383383
$attrRegExp = '#' . $this->_tokenRegex . '#S';
384384
$trArr = $this->_getTranslateData($attrRegExp, $tagHtml, array($this, '_getAttributeLocation'));
385385
if ($trArr) {
386-
$transRegExp = '# data-translate=' . $quoteHtml . '\[([^'.preg_quote($quoteHtml).']*)]' . $quoteHtml . '#i';
386+
$transRegExp = '# data-translate=' . $quoteHtml . '\[([^'.preg_quote($quoteHtml, '#').']*)]' . $quoteHtml . '#i';
387387
if (preg_match($transRegExp, $tagHtml, $m)) {
388388
$tagHtml = str_replace($m[0], '', $tagHtml); //remove tra
389389
$trAttr = ' data-translate=' . $quoteHtml

app/code/core/Mage/Dataflow/Model/Convert/Parser/Xml/Excel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function parse()
126126
continue;
127127
}
128128
else {
129-
if (preg_match('/ss:Name=\"'.preg_quote($worksheet).'\"/siU', substr($xmlTmpString, 0, $strposF))) {
129+
if (preg_match('/ss:Name=\"'.preg_quote($worksheet, '/').'\"/siU', substr($xmlTmpString, 0, $strposF))) {
130130
$xmlString = substr($xmlTmpString, $strposF);
131131
$isWorksheet = true;
132132
continue;

dev/tests/functional/tests/app/Mage/Catalog/Test/Handler/CatalogCategory/Curl.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected function getBlockId($landingName)
137137
$curl->write($url, [], CurlInterface::POST);
138138
$response = $curl->read();
139139
$curl->close();
140-
preg_match('~<option.*value="(\d+)".*>' . preg_quote($landingName) . '</option>~', $response, $matches);
140+
preg_match('~<option.*value="(\d+)".*>' . preg_quote($landingName, '~') . '</option>~', $response, $matches);
141141
$id = isset($matches[1]) ? (int)$matches[1] : null;
142142

143143
return $id;

lib/Zend/Cloud/DocumentService/Adapter/WindowsAzure.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ protected function _resolveAttributes(Zend_Service_WindowsAzure_Storage_TableEnt
525525
*/
526526
protected function _validateKey($key)
527527
{
528-
if (preg_match('@[/#?' . preg_quote('\\') . ']@', $key)) {
528+
if (preg_match('@[/#?' . preg_quote('\\', '@') . ']@', $key)) {
529529
throw new Zend_Cloud_DocumentService_Exception('Invalid partition or row key provided; must not contain /, \\, #, or ? characters');
530530
}
531531
}

lib/Zend/Db/Statement.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -180,20 +180,20 @@ protected function _stripQuoted($sql)
180180
// get the character for value quoting
181181
// this should be '
182182
$q = $this->_adapter->quote('a');
183-
$q = $q[0];
183+
$q = $q[0];
184184
// get the value used as an escaped quote,
185185
// e.g. \' or ''
186186
$qe = $this->_adapter->quote($q);
187187
$qe = substr($qe, 1, 2);
188-
$qe = preg_quote($qe);
188+
$qe = preg_quote($qe, '/');
189189
$escapeChar = substr($qe,0,1);
190190
// remove 'foo\'bar'
191191
if (!empty($q)) {
192-
$escapeChar = preg_quote($escapeChar);
192+
$escapeChar = preg_quote($escapeChar, '/');
193193
// this segfaults only after 65,000 characters instead of 9,000
194194
$sql = preg_replace("/$q([^$q{$escapeChar}]*|($qe)*)*$q/s", '', $sql);
195195
}
196-
196+
197197
// get a version of the SQL statement with all quoted
198198
// values and delimited identifiers stripped out
199199
// remove "foo\"bar"
@@ -207,7 +207,7 @@ protected function _stripQuoted($sql)
207207
// e.g. \" or "" or \`
208208
$de = $this->_adapter->quoteIdentifier($d);
209209
$de = substr($de, 1, 2);
210-
$de = preg_quote($de);
210+
$de = preg_quote($de, '/');
211211
// Note: $de and $d where never used..., now they are:
212212
$sql = preg_replace("/$d($de|\\\\{2}|[^$d])*$d/Us", '', $sql);
213213
return $sql;

lib/Zend/Http/Cookie.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public static function matchCookieDomain($cookieDomain, $host)
395395

396396
// Check for either exact match or suffix match
397397
return ($cookieDomain == $host ||
398-
preg_match('/\.' . preg_quote($cookieDomain) . '$/', $host));
398+
preg_match('/\.' . preg_quote($cookieDomain, '/') . '$/', $host));
399399
}
400400

401401
/**

0 commit comments

Comments
 (0)