mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
Merge pull request #1275 from vanhoofmaarten/fix/pattern-single-quote-escaping
Fix pattern single quote escaping
This commit is contained in:
commit
175675422e
@ -10,5 +10,7 @@ describe('getPattern', () => {
|
||||
expect(getPattern('\\')).toEqual('\\\\');
|
||||
expect(getPattern('\\/')).toEqual('\\\\/');
|
||||
expect(getPattern('\\/\\/')).toEqual('\\\\/\\\\/');
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
expect(getPattern("'")).toEqual("\\'");
|
||||
});
|
||||
});
|
||||
|
||||
@ -3,8 +3,12 @@
|
||||
* However, to use it in HTML or inside new RegExp() we need to
|
||||
* escape the pattern to become: '^\\d{3}-\\d{2}-\\d{4}$' in order
|
||||
* to make it a valid regexp string.
|
||||
*
|
||||
* Also, escape single quote characters, because the output uses single quotes for strings
|
||||
*
|
||||
* @param pattern
|
||||
*/
|
||||
export const getPattern = (pattern?: string): string | undefined => {
|
||||
return pattern?.replace(/\\/g, '\\\\');
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
return pattern?.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
||||
};
|
||||
|
||||
@ -1299,6 +1299,7 @@ export type ModelWithPattern = {
|
||||
readonly modified?: string;
|
||||
id?: string;
|
||||
text?: string;
|
||||
patternWithSingleQuotes?: string;
|
||||
};
|
||||
|
||||
"
|
||||
@ -2090,6 +2091,10 @@ export const $ModelWithPattern = {
|
||||
type: 'string',
|
||||
pattern: '^\\\\\\\\w+$',
|
||||
},
|
||||
patternWithSingleQuotes: {
|
||||
type: 'string',
|
||||
pattern: '^[a-zA-Z0-9\\\\']*$',
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
"
|
||||
@ -4695,6 +4700,7 @@ export type ModelWithPattern = {
|
||||
readonly modified?: string;
|
||||
id?: string;
|
||||
text?: string;
|
||||
patternWithSingleQuotes?: string;
|
||||
};
|
||||
|
||||
"
|
||||
@ -5931,6 +5937,10 @@ export const $ModelWithPattern = {
|
||||
type: 'string',
|
||||
pattern: '^\\\\\\\\w+$',
|
||||
},
|
||||
patternWithSingleQuotes: {
|
||||
type: 'string',
|
||||
pattern: '^[a-zA-Z0-9\\\\']*$',
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
"
|
||||
|
||||
@ -1499,6 +1499,10 @@
|
||||
"text": {
|
||||
"type": "string",
|
||||
"pattern": "^\\w+$"
|
||||
},
|
||||
"patternWithSingleQuotes": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-zA-Z0-9']*$"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2466,6 +2466,10 @@
|
||||
"text": {
|
||||
"type": "string",
|
||||
"pattern": "^\\w+$"
|
||||
},
|
||||
"patternWithSingleQuotes": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-zA-Z0-9']*$"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user