Skip to content

Instantly share code, notes, and snippets.

@andersonbosa
Forked from vills/url_encode.rb
Created May 18, 2022 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andersonbosa/3dea84843e2d8cb3004f2b8543e76bb0 to your computer and use it in GitHub Desktop.
Save andersonbosa/3dea84843e2d8cb3004f2b8543e76bb0 to your computer and use it in GitHub Desktop.
Percent encoding for URI conforming to RFC 3986. Ref: http://tools.ietf.org/html/rfc3986#page-12
require 'liquid'
require 'uri'
# Percent encoding for URI conforming to RFC 3986.
# Ref: http://tools.ietf.org/html/rfc3986#page-12
module URLEncoding
def url_encode(url)
return URI.escape(url, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
end
end
Liquid::Template.register_filter(URLEncoding)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment