Validate Content-Type by parsed media type instead of substring match (v1.x) (#2444)
This commit is contained in:
parent
369513df7b
commit
69749aa508
1 changed files with 271 additions and 4 deletions
|
|
@ -23,6 +23,23 @@ export default tseslint.config(
|
|||
{
|
||||
ignores: ['src/spec.types.ts']
|
||||
},
|
||||
{
|
||||
files: ['src/**/*.ts'],
|
||||
rules: {
|
||||
'no-restricted-syntax': [
|
||||
'error',
|
||||
{
|
||||
selector:
|
||||
":matches(CallExpression[callee.property.name='includes'], CallExpression[callee.property.name='indexOf'], " +
|
||||
"CallExpression[callee.property.name='startsWith'])[arguments.0.value='application/json']",
|
||||
message:
|
||||
"Substring-matching 'application/json' misclassifies Content-Type values whose media type is different " +
|
||||
"(e.g. 'text/plain; a=application/json') and mishandles parameters and case. " +
|
||||
'Parse the media type instead: isJsonContentType() from src/shared/mediaType.js.'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['src/client/**/*.ts', 'src/server/**/*.ts'],
|
||||
ignores: ['**/*.test.ts'],
|
||||
|
|
|
|||
Loading…
Reference in a new issue