RepoPilot

What edge cases are covered in the tests, especially around hyphens?

About sindresorhus/escape-string-regexp · 2 messages · last activity 5/18/2026

Question

What edge cases are covered in the tests, especially around hyphens?

RepoPilot

The tests in [test.js:L1-L24] cover two important edge cases around hyphens:

  1. PCRE compatibility [test.js:L11-L16]: The test verifies that hyphens in strings like 'foo - bar' are escaped as 'foo \\x2d bar' (hexadecimal escape). This ensures compatibility with PCRE (Perl Compatible Regular Expressions).

  2. Unicode flag compatibility [test.js:L18-L24]: The test checks that when a hyphen is escaped via escapeStringRegexp('-'), the result works correctly with the Unicode flag ('u') when used in a RegExp. This is important because Unicode mode has different regex semantics.

The primary test [test.js:L4-L9] also covers the core functionality by escaping a comprehensive set of special RegExp characters: \ ^ $ * + ? . ( ) | { } [ ]

These tests ensure that the library handles not just the basic special characters, but also the subtle case of hyphens which need special treatment depending on the regex mode being used.

FOLLOW_UPS:

  • What does the main function implementation look like?
  • Why is hyphen escaping treated differently than other characters?
  • Are there any other Unicode-related test cases?

Public Q&A. Generated by RepoPilot from the actual source of sindresorhus/escape-string-regexp. AI answers can be incomplete or stale — verify before relying on them.