-
Notifications
You must be signed in to change notification settings - Fork 4.5k
(assert-internal): stringLike function does not support multiline strings #17691
Copy link
Copy link
Closed
Closed
Copy link
Labels
@aws-cdk/aws-lambdaRelated to AWS LambdaRelated to AWS LambdabugThis issue is a bug.This issue is a bug.effort/smallSmall work item – less than a day of effortSmall work item – less than a day of effortp2
Description
What is the problem?
I am writing an unit test using the stringLike() as suggested by @nija-at @ #16827
The value being checked contains line breaks (\n) which fails on current implementation of stringLike()
Reproduction Steps
Copied the code from the aws-cdk:
function escapeRegex(s) { return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');}
let regex = `^${"*includeHeaders*".split('*').map(escapeRegex).join('.*')}$`
// value above is "^.*includeHeaders.*$"
let regexp = new RegExp(regex);
let value = "something includeHeaders\nsomething"
let regexMatch = regexp.test(value);
console.log(regexp.test(value));output is "false"
What did you expect to happen?
to return true
What actually happened?
it returned false
CDK CLI Version
1.134.0
Framework Version
No response
Node.js Version
12
OS
mac
Language
Typescript
Language Version
No response
Other information
Issue can be fixed by:
- let regexp = new RegExp(regex);
+ let regexp = new RegExp(regex, 'm');
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline
I am going to submit a PR soon.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
@aws-cdk/aws-lambdaRelated to AWS LambdaRelated to AWS LambdabugThis issue is a bug.This issue is a bug.effort/smallSmall work item – less than a day of effortSmall work item – less than a day of effortp2