Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing simple preg calls with less expensive alternates #341

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/code/Mage/Core/Helper/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ public function addRequestParam($url, $param)
public function removeRequestParam($url, $paramKey, $caseSensitive = false)
{
$regExpression = '/\\?[^#]*?(' . preg_quote($paramKey, '/') . '\\=[^#&]*&?)/' . ($caseSensitive ? '' : 'i');
while (preg_match($regExpression, $url, $mathes) != 0) {
$paramString = $mathes[1];
if (preg_match('/&$/', $paramString) == 0) {
while (preg_match($regExpression, $url, $matches) !== 0) {
$paramString = $matches[1];
// if ampersand is at the end of $paramString
if (substr($paramString, -1, 1) != '&') {
$url = preg_replace('/(&|\\?)?' . preg_quote($paramString, '/') . '/', '', $url);
} else {
$url = str_replace($paramString, '', $url);
Expand Down
2 changes: 1 addition & 1 deletion app/code/Mage/Core/Model/Design/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public function getViewFile($file, array $params = array())
*/
protected function _extractScope($file, array &$params)
{
if (preg_match('/\.\//', str_replace('\\', '/', $file))) {
if (strpos(str_replace('\\', '/', $file), './') !== false) {
throw new Magento_Exception("File name '{$file}' is forbidden for security reasons.");
}
if (false !== strpos($file, self::SCOPE_SEPARATOR)) {
Expand Down
2 changes: 1 addition & 1 deletion app/code/Mage/GoogleAnalytics/Block/Ga.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getPageTrackingCode($accountId)
{
$pageName = trim($this->getPageName());
$optPageURL = '';
if ($pageName && preg_match('/^\/.*/i', $pageName)) {
if ($pageName && substr($pageName, 0, 1) == '/' && strlen($pageName) > 1) {
$optPageURL = ", '{$this->jsQuoteEscape($pageName)}'";
}
return "
Expand Down
4 changes: 2 additions & 2 deletions app/code/Mage/Webhook/Controller/Webapi/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ private function _filterTopicsByApiUser($topics, $userId)
$readableResources = array();
foreach ($resourceIds as $resource) {
if (preg_match("/\/get/", $resource)) { // TODO: Should be allowed to be anything, not just get
$result = preg_split("/\//", $resource);
$result = explode("/", $resource);
$readableResources[] = $result[0];
}
}

$resultTopics = array();
foreach($topics as $topic) {
$topic = str_replace("\/", "/", $topic);
$array = preg_split("/\//", $topic);
$array = explode("/", $topic);
if (in_array($array[0], $readableResources)) {
$resultTopics[] = $topic;
}
Expand Down