Collapse whitespace issue with
See original GitHub issueHad an issue that stemmed from Cypress testing library but debugged into Dom testing library. The issue is this function.
When searching for text with a non breaking space such as “٤ UK£”, the regex replaces the nbsp into a space. It’s fairly obvious why the regex was used, but it’s effectively converting all types of spaces into a “regular space”. This then causes the text match to fail.
In my opinion, that’s an unintentional side effect of collapseWhitespace
.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:10 (1 by maintainers)
Top Results From Across the Web
  and HTML Space Challenges and Tricks | Mailtrap Blog
Nbsp stands for non-breaking space, meaning that strings separated with this entity will not be separated and put into separate lines. But ...
Read more >Non-collapsing but still (line-)breakable space in HTML?
Regular whitespace gets collapsed (a run of spaces looks the same as a single space), and at the non-breaking space ( ) the line...
Read more >Non-breaking space - Wikipedia
In word processing and digital typesetting, a non-breaking space, , also called NBSP, ... consecutive whitespace characters from collapsing into a single space....
Read more >Non-Breaking Space in HTML
create white space between words or web page elements ... To insert a non-breaking space you would use: ... Problems with Non-Breaking...
Read more >359303 - Non-breaking spaces (nbsp) not copied as such
Reproducible: Always Steps to Reproduce: 1. Copy text containing a non-breaking space character ( or UTF-8 0xA0) to the clipboard. 2. Paste into...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m getting a similar issue with non-breaking spaces and I can’t seem to find a way to target them easily. This is what I have tried:
I have not tried using a custom text matcher function or a custom normalizer, but I feel like there is probably an easy built-in way to do this without going too crazy on customizations. Any ideas?
I absoutely can try, there doesn’t seem to be a way to configure this globally though (I have to do this in many places). Is that something that you could see being added?
I’m not sure I agree with the docs here:
Consider the following " a b ". I would expect the first and last spaces to be removed but there are no “multiple adjacent whitespace characters”. So the inner space (non breaking) should have been preserved.
I’m using the Intl.NumberFormat in my application which is outputting that nbsp, and then in Cypress I’m querying for that text which is highlighting that mismatch. Would the default normalizer benefit from collapsing multiple spaces but preserving the “type of space”?
Alternatively, should the same normalization be applied to the textContent?