Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: single-quoted attribute value syntax support #287

Merged
merged 1 commit into from Mar 3, 2024

Conversation

mdk000
Copy link
Contributor

@mdk000 mdk000 commented Feb 29, 2024

Hi @leizongmin!

First of all thank you for creating this package. We have been using it for sanitizing html and put it inside JSON files. It can be done in two ways:

  • { "html": "<a href=\"#\">Hello</a>" }
  • { "html": "<a href='#'>Hello</a>" }

but the default config output is:

  • { "html": "<a href="#">Hello</a>" }

We would like to use default config and don't create any custom rules via safeAttrValue or onIgnoreTagAttr, but we need to have single-quoted attribute value syntax for sanitized output. Accodring to whatwg spec, single quoted approach is also valid and supports values containing whitespaces.

I've created a PR. Now it's available use new quotedAttributeValueSyntax config option. Default behaviour left intact so changes can be treated as enhancement.

Let me know what you think

@leizongmin
Copy link
Owner

Hi, @mdk000 . Thanks for you PR.

I think it might be better to change quotedAttributeValueSyntax: 'single' | 'double' to singleQuotedAttributeValue: true | false. Only when singleQuotedAttributeValue is set to true, the attribute values will be wrapped in single quotes. If singleQuotedAttributeValue is not set or set to false, the attribute values will be wrapped in double quotes as usual.

@mdk000 mdk000 force-pushed the attribute-value-syntax branch 2 times, most recently from 60f2582 to a82fea0 Compare March 1, 2024 07:27
@mdk000
Copy link
Contributor Author

mdk000 commented Mar 1, 2024

@leizongmin thanks for suggestion, I've corrected it, please check

When do you plan to release new version with this feature?

@leizongmin leizongmin merged commit bedb0c0 into leizongmin:master Mar 3, 2024
7 checks passed
@leizongmin
Copy link
Owner

@mdk000 I just merged this MR and released a new version xss@1.0.15.

@mdk000 mdk000 deleted the attribute-value-syntax branch March 3, 2024 21:49
@mdk000
Copy link
Contributor Author

mdk000 commented Mar 3, 2024

@leizongmin awesome! thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants