Skip to content

(assert-internal): stringLike function does not support multiline strings #17691

@diegotry

Description

@diegotry

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.

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-lambdaRelated to AWS LambdabugThis issue is a bug.effort/smallSmall work item – less than a day of effortp2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions