-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Escaping special regex chars * Separating test function into its own file * Uncommenting line * Added functionality to prevent double escaping and made testing function more debug friendly --------- Co-authored-by: Reinier Cruz <[email protected]>
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as assert from "assert"; | ||
import { escapeRegExp } from "../../panels/TcpDumpPanel"; | ||
|
||
describe("testEscapeRegExp", () => { | ||
it("should escape special regex characters", () => { | ||
const input = "a.b*c?d+e^f$g|h(i)j{k}l[m]n\\o"; | ||
const expected = "a\\.b\\*c\\?d\\+e\\^f\\$g\\|h\\(i\\)j\\{k\\}l\\[m\\]n\\\\o"; | ||
const escapedInput = escapeRegExp(input); | ||
assert.equal(escapedInput, expected); | ||
}); | ||
|
||
it("should not double escape already escaped characters", () => { | ||
const input = "a\\.b\\*c\\?d\\+e\\^f\\$g\\|h\\(i\\)j\\{k\\}l\\[m\\]n\\\\o"; | ||
const expected = "a\\.b\\*c\\?d\\+e\\^f\\$g\\|h\\(i\\)j\\{k\\}l\\[m\\]n\\\\o"; | ||
const escapedInput = escapeRegExp(input); | ||
assert.equal(escapedInput, expected); | ||
}); | ||
|
||
it("should return an empty string if input is empty", () => { | ||
const input = ""; | ||
const expected = ""; | ||
const escapedInput = escapeRegExp(input); | ||
assert.equal(escapedInput, expected); | ||
}); | ||
|
||
it("should return the same string if no special characters", () => { | ||
const input = "abcdefg"; | ||
const expected = "abcdefg"; | ||
const escapedInput = escapeRegExp(input); | ||
assert.equal(escapedInput, expected); | ||
}); | ||
}); |