Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Pick longest match always

  • Loading branch information...
commit 57682650a39dd8879957c5e3f74845803be1fe4d 1 parent 4622e70
@Seldaek Seldaek authored committed
Showing with 9 additions and 4 deletions.
  1. +9 −4 src/Composer/Json/JsonManipulator.php
View
13 src/Composer/Json/JsonManipulator.php
@@ -164,16 +164,21 @@ public function removeSubNode($mainNode, $name)
}
if (preg_match('{"'.preg_quote($name).'"\s*:}i', $children)) {
- if (preg_match('{"'.preg_quote($name).'"\s*:\s*(?:[0-9.]+|null|true|false|"[^"]+"|\{'.self::$RECURSE_BLOCKS.'\})}', $children, $matches)) {
- $children = preg_replace('{,\s*'.preg_quote($matches[0]).'}i', '', $children, -1, $count);
+ if (preg_match_all('{"'.preg_quote($name).'"\s*:\s*(?:[0-9.]+|null|true|false|"[^"]+"|\{'.self::$RECURSE_BLOCKS.'\})}', $children, $matches)) {
+ $bestMatch = '';
+ foreach ($matches[0] as $match) {
+ if (strlen($bestMatch) < strlen($match)) {
+ $bestMatch = $match;
+ }
+ }
+ $children = preg_replace('{,\s*'.preg_quote($bestMatch).'}i', '', $children, -1, $count);
if (1 !== $count) {
- $children = preg_replace('{'.preg_quote($matches[0]).'\s*,?\s*}i', '', $children, -1, $count);
+ $children = preg_replace('{'.preg_quote($bestMatch).'\s*,?\s*}i', '', $children, -1, $count);
if (1 !== $count) {
return false;
}
}
}
-
}
if (!trim($children)) {
Please sign in to comment.
Something went wrong with that request. Please try again.