Skip to content

Commit adc40e6

Browse files
committed
Fixed an issue with unescaped carets at the beginning of a character class
1 parent 85a0077 commit adc40e6

File tree

5 files changed

+9
-3
lines changed

5 files changed

+9
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "s9e/regexp-builder",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"type": "library",
55
"description": "Single-purpose library that generates regular expressions that match a list of strings.",
66
"homepage": "https://github.com/s9e/RegexpBuilder/",

src/Escaper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Escaper
1212
/**
1313
* @var array Characters to escape in a character class
1414
*/
15-
public $inCharacterClass = ['-' => '\\-', '\\' => '\\\\', ']' => '\\]'];
15+
public $inCharacterClass = ['-' => '\\-', '\\' => '\\\\', ']' => '\\]', '^' => '\\^'];
1616

1717
/**
1818
* @var array Characters to escape outside of a character class

tests/BuilderTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ public function getBuilderTests()
132132
'(?:\\n|.)',
133133
['meta' => ['.' => '.'], 'output' => 'PHP']
134134
],
135+
[
136+
['^', '_'],
137+
'[\\^_]'
138+
],
135139
];
136140
}
137141
}

tests/EscaperTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public function getEscapeCharacterClassTests()
2424
return [
2525
['-', '\\-'],
2626
['\\', '\\\\'],
27+
['[', '['],
28+
['^', '\\^'],
2729
[']', '\\]'],
2830
['/', '\\/'],
2931
['/', '/', '#'],

tests/SerializerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function getSerializerTests()
111111
[94],
112112
[123]
113113
],
114-
'[\\]^{]'
114+
'[\\]\\^{]'
115115
],
116116
[
117117
[

0 commit comments

Comments
 (0)