kmthorsnes
(Karl-Magnus Thorsnes)
January 16, 2023, 7:47am
1
Hi,
When looking into the reported bugs in our code i get an error off
Unexpected unknown type selector ""
Which I cannot understand when the code it reports of is:
@media (max-width:1400px) and (min-width:1100px) {
.header-text-longname {
display:none;
}
.header-text-shortname {
display: inline;
}
}
Is there something here I’m not spotting?
gab
(Gabriel Vivas)
January 19, 2023, 12:00pm
3
Hi @kmthorsnes ,
It seems you have an invisible character at that position!
@media (max-width:1400px) and (min-width:1100px) {
.header-text-longname {
display:none;
}
.header-text-shortname {
display: inline;
}
}<0x200b>
You can enable invisible characters in your IDE to catch these more easily.
I created a ticket since I think it would be very cool if Sonar could warn about this
Best,
Gabriel
kmthorsnes
(Karl-Magnus Thorsnes)
January 19, 2023, 1:27pm
4
Thank you Gabriel,
This was very upclearing.
All the best
gab
(Gabriel Vivas)
January 19, 2023, 1:37pm
5
You’re welcome!
Any idea how that character got in there? Copy-paste? Key-combination? Something else?
Here’s the Github ticket, it shows how this can actually create a CSS bug that might be hard to find:
opened 01:18PM - 19 Jan 23 UTC
| Label | Description |
| --- | --- |
| Subject | CSS parser error on invisibl… e character <0x200b> |
| Community | https://community.sonarsource.com/t/unexpected-unknown-type-selector/81316 |
### Explanation
User reported an unclear error message appearing on otherwise normal CSS code:
```css
.header-text-longname {
display: none;
}
.header-text-shortname {
display: inline;
}
```
> Unexpected unknown type selector ""
This error is raised by Sonar when an invisible character `<0x200b>` is placed where a selector is expected. In this case, on lines 3 and 6 after the braces.
The [`<0x200b>`](https://unicodemap.org/details/0x200B/index.html) character is in the range `[0x2000 - 0x206F]` "General Punctuation".
Stylint also raises an error, as can be confirmed in the online playground, see working example [1].
The error message changes depending on the placement of the invisible character.
> Unable to lint CSS: SyntaxError: The string did not match the expected pattern.
> Unknown word (CssSyntaxError)
### Suggestion
(Perhaps also in JavaScript and TypeScript):
* Verify runtime behavior vs parser behavior for invisible characters to see if it could produce bugs.
* Consider transparently stripping/ignoring invisible characters to avoid parsing errors.
* Consider warning about the presence of an invisible character (instead of an unclear error).
* Consider implementing a new rule in SonarText that raises on invisible characters that may cause parsing errors. There is [precedent for this](https://rules.sonarsource.com/text) and perhaps security implications.
[1] [Stylelint playground example](https://stylelint.io/demo/#N4Igxg9gJgpiBcIB0ALGBDWAnAtAFxgA88cAbCAOwHML0BbGAAmAB0LHGoBLAZwAdS6AJ7xGFSjADcbAL6BoAjZtUGbPiIkeKCFjy0GzNh279BIxlwqkLU2QoogANCB5CKedIQTgePR+EoAZlxUXqzsjCwgWACupDA8kaJhHByR6BTi7nhclDjiONEUANbiAO4UiYx4MTAOhilpJDFxeRAFxWUVCFU1deGpIABG5GBFrTgwdHx4QpXV0bX1A5DkuPkWAG7oVlA4aIRzvUsR-nQMbuOT07Pd84v9J2DRPHgQdDh8WBB8MDpC43ReDwLFQcFtcAFCmBspRDgs+ikTrAwIIsOgYRQcMMIKNxlBogIuGB0TAcE8Xm8Pl8fjouPE4fdEZFkaj0TlMdjcfl8YTiQQqd9ftl6d0ANrHDh3BGIgwPJkgYLiLAwSriuUyyKQCg8GBPbIbUk8qx8+I4UpcPAoHDcAIBX4wC5bUgLBIgCUpAC67pkxw90oGLPQaIxWJGY3ymm0lvSu0+gr+OAgBqwWC4sFdoilx0iAUoJAC9C4pH+3IJxpJeXoIszRweObzOALgOLAKBIJwVAdvyJjcLLaKMCEpW0UAZ-pOkIo0PZZO2YHGhX46DAMF28fR2jH2ZAk+nuSsFAwuCoaO4DpI+XE2vcFCgQd23GVe66Nfh293IfyhRKEHKW7rIADkIARogwoY4uGbRGkSFY6nE0LaBmPRvgBQEgVW1q6qyn5tFwUxRukeD-vKDDcOgjYYHg0TKpWYFfh0v4vshjINCAeirh2qa7EGGA8OMmzbGmxGsdy8Qrre7b8LqXBBGAFo3K+LEDKWvIVuiOB4XwUY4M01bMeOkQqeW-JwbqrxYEhWYAfkVwzDgPAQNRK7CcpbTqGi9mTESEDkNqLknOsFBOmm1qOcMpI8IImhkm85x4JZtbyoFwWxhAwIhup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XmzeOrqYaFmX3r2PUYO5TpXKvxfEZ56ov7kbtw2X1v8BJmyuEY+sm5HypVgt4MhvkQEPh2y4cTAEeyjksCQM-nb4G1loh0CvrgOImB2yQrW0zrxFAw8R8QcmyeclgQJcYAAFnGon8PGd8h5oLb9WPXwEptTqmTBMSmO4qa8bSxqSPx5dVR9PSGus93+N50M4JFGTMcLM659Udt5RTJiTk2ZOZH1bJSWBk6C3LkHM-Wsn9OG3BPPnxBzW40OrTXRNULggxoj8ggQOeK6uScbv++TtaU1Nr79TEf-kXPfbKOl4Za-Xjd-3-+Y-4-dOaQNxX8NVu8P9zcAJv9cAH9D9-8hdkNUNZ0dUd9StpoBohp+ssBAVe9hs4VRtcUOVMVJsxtps+U5thUICUDNoSlBgLAgD1d38KMv9KDcBqDaCGcftTc+ckCvpmDMIeBxI7wLhWDaBppLxchBFIZICNJYx98BsZkZYcDoVuU8UJtlCUUZt+VbZ5tkC79I8xdM4k1Jc+0yMtd+cKDdDUFVcJcTdskApP8aMpDttO89JLtzCNo1gm8+oW8p50cQ9b93DEZytkYiESkBAiAmCLDuoYBep+ooo+Ia8bFIcb9WIpCoiYiD5Bo+JrMCddML9AMr9wD-Cys0i5oHpzwrEIca5kjRZeCSi3IFpyju09EKsiE+pohwoIiAiZgdoEjyM68HCtAdAm1Ywq9G8sMa1BCSB4Y21apRYD9fovMEDyM2iOiaNQZilwda8kivFpicBmsRwKitiqidjtgEYrArDiN9MGDWN+9bVOMaNdjzijdDDGdEC2NJFddtxHj9C1cbDBkwCodWJvjNknCrdpNKhXD5Rdj8gx4vCqQfDBt20UgR9WIk4YAAA1U4vSL9HhCAGeXOLfT0eod6GQEAGQIAA)
Cheers,
Gabriel
kmthorsnes
(Karl-Magnus Thorsnes)
January 19, 2023, 4:03pm
6
Thank you,
To be honest i am not really sure. From what I can see this part of the code has not been touched for 3 years - and by someone who is not working here anymore , and I cannot spot the character in github.
However, now I do see it in VSCode, which I did not before. Also not able to spot this when i look at the file in raw view in github.
tor. 19. jan. 2023 kl. 14:47 skrev Gabriel Vivas via Sonar Community <notifications@sonarcommunity.discoursemail.com >:
1 Like
gab
(Gabriel Vivas)
January 23, 2023, 10:35am
7
That’s intriguing.
In case you want to dig further, git in your terminal can display the invisible characters:
git diff --ws-error-highlight=all
If you want to check the Github raw file, you can use cat
to highlight invisible characters. In macOS with cat -v
, or in Linux with cat -A
.
For example, you can try to show that file in the terminal using cURL:
$ curl -s https://gist.githubusercontent.com/gabriel-vivas-sonarsource/14e52ac0b109931a17bbee1b46b13fe4/raw/4d63d3fe6cdbaebe3e4a0d250e55251f7bfe2870/zero-width-space-css-bug.html | cat -v
Anyway, keep in mind that if the character is at the end of the file, there would be no actual bug. Only if you have a selector below it will be ignored by the browser.
Best,
Gabriel