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

V2 Can we remove CssParser.convert_uris #157

Open
stoivo opened this issue May 27, 2024 · 1 comment
Open

V2 Can we remove CssParser.convert_uris #157

stoivo opened this issue May 27, 2024 · 1 comment

Comments

@stoivo
Copy link
Contributor

stoivo commented May 27, 2024

I am looking to try to remove the use of regex and wonder if we can remove if feature completely CssParser.convert_uris

# Make <tt>url()</tt> links absolute.
#
# Takes a block of CSS and returns it with all relative URIs converted to absolute URIs.
#
# "For CSS style sheets, the base URI is that of the style sheet, not that of the source document."
# per http://www.w3.org/TR/CSS21/syndata.html#uri
#
# Returns a string.
#
# ==== Example
# CssParser.convert_uris("body { background: url('../style/yellow.png?abc=123') };",
# "http://example.org/style/basic.css").inspect
# => "body { background: url('http://example.org/style/yellow.png?abc=123') };"
def self.convert_uris(css, base_uri)
base_uri = Addressable::URI.parse(base_uri) unless base_uri.is_a?(Addressable::URI)
css.gsub(URI_RX) do
uri = Regexp.last_match(1).to_s.gsub(/["']+/, '')
# Don't process URLs that are already absolute
unless uri.match(%r{^[a-z]+://}i)
begin
uri = base_uri.join(uri)
rescue
nil
end
end
"url('#{uri}')"
end
end

It as added 17 years ago 4215785. I think when it's used in premailer we want to have all absolute urls not relative. If thats the reason we should that code should probably be in premailer instead.

Maybe we should just keep it to reduce the braking changes. Just want to ask

@grosser
Copy link
Contributor

grosser commented May 27, 2024

generally +1 for removing regex hackery, but hard to know who uses this 😞
If it's not causing trouble I'd in doubt leave it, but if it is then not against moving it

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

No branches or pull requests

2 participants