prettier / prettier/plugin-xml

Whitespace is incorrectly preserved when `xmlWhitespaceSensitivity` is set to `ignore`

Open
#789 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
278
Forks
46
Avg merge
1m
Merged PRs (30d)
13

Description

According to the XML specification, only \t, \n, \r, and (space character) are considered whitespace and are affected by the xml:space attribute. As it has been already raised in #768, the plugin used String#trim() to remove whitespace characters, affecting also other non-XML whitespace characters:

This issue has been fixed in 6170e95. However, the fix still affects most of the characters mentioned above due to the usage of the \s character class and the issue described originally in #768 still persists.

Probably the easiest way to fix the issue is to replace the \s character class with the (space character):

const content = chardata.TEXT.replaceAll(/^[\t\n\r ]+|[\t\n\r ]+$/g, "");

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Search the XML plugin implementation for xmlWhitespaceSensitivity and the current String#trim or \s-based handling. Reproduce the behavior with XML text containing tabs, line breaks, spaces, and the listed non-XML whitespace characters. Done means only tab, newline, carriage return, and space are trimmed when sensitivity is set to ignore.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.