Skip to content

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

Merged
curbengh merged 1 commit intohexojs:masterfrom
curbengh:encode-url-style
Sep 22, 2019
Merged

fix(html_tag): encode url() in style tag#101
curbengh merged 1 commit intohexojs:masterfrom
curbengh:encode-url-style

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.

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.

3 participants