parse_theme: ignore whitespace around KV pairs and skip malformed lines
Before adoption: this commit came in with the history the project adopted, so no landing records it.
strtok_r(3) returns NULL if no tokens are found. Hence, we can't safely dereference key or value without first checking that they're not NULL, such as in the call to strcasecmp(3) later. However, as we need to do more than simply tokenization when we iterate through line, don't use strtok_r(3) such that we don't iterate through the same section of the string multiple times. The freedesktop icon specification states that the format for .theme files is mostly similar to that of the desktop file specification[1]: > Both the icon theme description file and the icon data files are > ini-style text files, as described in the desktop file specification. > They don't have any encoding field. Instead, they must always > be stored in UTF-8 encoding. The desktop entry specification has support for comments[2]: > Lines beginning with a # and blank lines are considered comments and > will be ignored, however they should be preserved across reads and > writes of the desktop entry file. This patch will also account for those. While we're at it, handle whitespace surrounding KV pairs properly. The desktop entry specification explicitly states that space space before and after the equals sign is to be ignored[3]: > Space before and after the equals sign should be ignored; the = sign > is the actual delimiter. Although it also bounds the character set that a key may be comprised: > Only the characters A-Za-z0-9- may be used in key names. don't bother validating key names: we only lookup known good keys, and as such malformed key names would be ignored anyway. [1] https://specifications.freedesktop.org/icon-theme/latest/#file_formats [2] https://specifications.freedesktop.org/desktop-entry/latest/basic-format.html#comments [3] https://specifications.freedesktop.org/desktop-entry/latest/basic-format.html#entries
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Signed-off-by: Rahul Sandhu <nvraxn@posteo.uk>
Diff stats
2 files+52 added−6 removed
- other:+52 added−6 removed