File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
3
+ ## Next
4
+ - Fixed a crash occurring when parsing heuristics for ` .txt ` files ([ #16 ] ( https://github.com/Nixinova/LinguistJS/issues/16 ) ).
5
+
3
6
## 2.5.2
4
7
* 2022-06-28*
5
8
- Fixed file extensions with multiple delimiters not being prioritised over basic extensions.
Original file line number Diff line number Diff line change @@ -10,15 +10,25 @@ export default function pcre(regex: string): RegExp {
10
10
replace ( match , '' ) ;
11
11
[ ...flags ] . forEach ( flag => finalFlags . add ( flag ) ) ;
12
12
}
13
- // Remove invalid syntax
13
+ // Remove PCRE-only syntax
14
14
replace ( / ( [ * + ] ) { 2 } / g, '$1' ) ;
15
15
replace ( / \( \? > / g, '(?:' ) ;
16
16
// Remove start/end-of-file markers
17
17
if ( / \\ [ A Z ] / . test ( finalRegex ) ) {
18
- replace ( / \\ A / g, '^' ) . replace ( / \\ Z / g, '$' ) ;
18
+ replace ( / \\ A / g, '^' ) ;
19
+ replace ( / \\ Z / g, '$' ) ;
19
20
finalFlags . delete ( 'm' ) ;
20
21
}
21
- else finalFlags . add ( 'm' ) ;
22
+ else {
23
+ finalFlags . add ( 'm' ) ;
24
+ }
25
+ // Reformat free-spacing mode
26
+ if ( finalFlags . has ( 'x' ) ) {
27
+ finalFlags . delete ( 'x' ) ;
28
+ replace ( / # .+ / g, '' ) ;
29
+ replace ( / ^ \s + | \s + $ | \n / gm, '' ) ;
30
+ replace ( / \s + / g, ' ' ) ;
31
+ }
22
32
// Return final regex
23
33
return RegExp ( finalRegex , [ ...finalFlags ] . join ( '' ) ) ;
24
34
}
You can’t perform that action at this time.
0 commit comments