Skip to content

Commit b7b94b4

Browse files
committed
fix: invalid named argument string on parse flags
1 parent bc5bc8e commit b7b94b4

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/ColorTag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
class ColorTag
2424
{
2525
// regex used for removing color tags
26-
public const STRIP_TAG = '/<[\/]?[a-zA-Z=;]+>/';
26+
public const STRIP_TAG = '/<[\/]?[a-zA-Z0-9=;]+>/';
2727

2828
// Regex to match tags/
29-
public const MATCH_TAG = '/<([a-zA-Z=;_]+)>(.*?)<\/\\1>/s';
29+
public const MATCH_TAG = '/<([a-zA-Z0-9=;_]+)>(.*?)<\/\\1>/s';
3030

3131
// color
3232
public const BLACK = 'black';

src/Flags.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ public static function filterBool($val, $enable = true)
299299
}
300300

301301
/**
302+
* check next is option value
303+
*
302304
* @param mixed $val
303305
*
304306
* @return bool
@@ -315,8 +317,22 @@ public static function nextIsValue($val): bool
315317
return true;
316318
}
317319

318-
// it isn't option or named argument
319-
return $val[0] !== '-' && false === strpos($val, '=');
320+
// is not option name.
321+
if ($val[0] !== '-') {
322+
// ensure is option value.
323+
if (false === strpos($val, '=')) {
324+
return true;
325+
}
326+
327+
// is string value, but contains '='
328+
[$name,] = explode('=', $val, 2);
329+
330+
// named argument OR invlaid: 'some = string'
331+
return false === self::isValidArgName($name);
332+
}
333+
334+
// is option name.
335+
return false;
320336
}
321337

322338
/**

src/Style.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ class Style
6767
* Regex to match tags
6868
*
6969
* @var string
70+
* @deprecated please use ColorTag::MATCH_TAG
7071
*/
71-
public const COLOR_TAG = '/<([a-zA-Z=;]+)>(.*?)<\/\\1>/s';
72+
public const COLOR_TAG = '/<([a-zA-Z0-9=;]+)>(.*?)<\/\\1>/s';
7273

7374
/**
7475
* @var self

0 commit comments

Comments
 (0)