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

Continuation of #96 (comment)

Regex is based on external_link.js

@curbengh curbengh requested a review from a team September 22, 2019 00:59
@curbengh curbengh mentioned this pull request Sep 22, 2019
@coveralls
Copy link

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
Copy link

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)}")`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@SukkaW
Copy link
Member

SukkaW commented Sep 22, 2019

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

@curbengh
Copy link
Contributor Author

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

p {
  background: url("foo.jpg");
}

@curbengh curbengh merged commit 0b1f3d0 into hexojs:master Sep 22, 2019
@curbengh curbengh deleted the encode-url-style branch September 22, 2019 08:50
@curbengh curbengh mentioned this pull request Sep 23, 2019
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

3 participants