A debugging story about 2 identical (looking) strings that weren’t so identical after all.

submited by
Style Pass
2025-01-06 06:30:02

So I stumbled upon this interesting case where 2 identical-looking strings were flagged as different by my test case. Here’s what I was looking at:

The test was for a property to return relativeDate. It was a simple test that checked if a formatted date string matched the expected output.

After starting at these similar strings and hours of re-running the test, hoping it to work (because by the looks of it, it felt right to the naked eye), I tried to dig deeper into what was actually going on.

To understand what was different between these strings, I printed out each character’s Unicode value using the codeUnits property:

That 8239 is actually a “Narrow No-Break Space” character (32 is the regular space) which was being used internally by the intl package’s DateFormat.

The no-break space keeps certain text elements together, preventing awkward line breaks that could harm readability. This is particularly important in use cases like: - Time formats (like our case) - Units of measurement (e.g., “100 km”) - Currency amounts (e.g., “$ 100”) - Other cases where breaking text could lead to confusion

Leave a Comment