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

fix(html_tag): encode url() in style tag #101

Merged
merged 1 commit into from Sep 22, 2019

Conversation

@curbengh
Copy link
Contributor

commented Sep 22, 2019

Continuation of #96 (comment)

Regex is based on external_link.js

@curbengh curbengh requested a review from hexojs/core Sep 22, 2019
@curbengh curbengh referenced this pull request Sep 22, 2019
@coveralls

This comment has been minimized.

Copy link

commented Sep 22, 2019

Coverage Status

Coverage increased (+0.03%) to 95.105% when pulling 1f2d148 on curbengh:encode-url-style into 560592d on hexojs:master.

1 similar comment
@coveralls

This comment has been minimized.

Copy link

commented Sep 22, 2019

Coverage Status

Coverage increased (+0.03%) to 95.105% when pulling 1f2d148 on curbengh:encode-url-style into 560592d on hexojs:master.

@@ -30,6 +30,11 @@ function htmlTag(tag, attrs, text, escape = true) {
}

if (escape && text && tag !== 'style') text = escapeHTML(String(text));
if (text && tag === 'style') {
text = text.replace(/url\(['"](.*?)['"]\)/gi, (urlAttr, url) => {
return `url("${encodeURL(url)}")`;

This comment has been minimized.

Copy link
@curbengh

curbengh Sep 22, 2019

Author Contributor

this is necessary (instead of return encodeURL(urlAttr)) to avoid encoding single/double quote.

@SukkaW

This comment has been minimized.

Copy link
Member

commented Sep 22, 2019

Many css properties' value could be URLs. For example, background and background-image.

@curbengh

This comment has been minimized.

Copy link
Contributor Author

commented Sep 22, 2019

My understanding is that url has to be wrapped in url("") to be used in background property,

p {
  background: url("foo.jpg");
}
@SukkaW
SukkaW approved these changes Sep 22, 2019
@curbengh curbengh merged commit 0b1f3d0 into hexojs:master Sep 22, 2019
3 checks passed
3 checks passed
Travis CI - Pull Request Build Passed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
coverage/coveralls Coverage increased (+0.03%) to 95.105%
Details
@curbengh curbengh deleted the curbengh:encode-url-style branch Sep 22, 2019
@curbengh curbengh referenced this pull request Sep 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.