File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
packages/openapi-ts/src/tsc Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -63,4 +63,14 @@ describe('createRegularExpressionLiteral', () => {
63
63
64
64
expect ( result . text ) . toBe ( '//' ) ;
65
65
} ) ;
66
+
67
+ it ( 'should handle patterns with already correctly escaped slashes' , ( ) => {
68
+ const result = createRegularExpressionLiteral ( {
69
+ text : '^data:image\\/svg\\+xml;base64,[A-Za-z0-9+\\/]+=*$' ,
70
+ } ) ;
71
+
72
+ expect ( result . text ) . toBe (
73
+ '/^data:image\\/svg\\+xml;base64,[A-Za-z0-9+\\/]+=*$/' ,
74
+ ) ;
75
+ } ) ;
66
76
} ) ;
Original file line number Diff line number Diff line change @@ -1084,8 +1084,8 @@ export const createRegularExpressionLiteral = ({
1084
1084
const patternContent =
1085
1085
text . startsWith ( '/' ) && text . endsWith ( '/' ) ? text . slice ( 1 , - 1 ) : text ;
1086
1086
1087
- // Escape forward slashes in the pattern content
1088
- const escapedPattern = patternContent . replace ( / \/ / g, '\\/' ) ;
1087
+ // Escape forward slashes in the pattern content, but only if they're not already escaped
1088
+ const escapedPattern = patternContent . replace ( / (?< ! \\ ) \/ / g, '\\/' ) ;
1089
1089
1090
1090
// Wrap with forward slashes
1091
1091
const textWithSlashes = `/${ escapedPattern } /` ;
You can’t perform that action at this time.
0 commit comments