Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrote URLRecode to Ruby to reduce Perl dependencies
so for package management maybe Perl will not be needed specifically for "yast2 repositories" it was the only Perl dependency
- Loading branch information
Showing
3 changed files
with
64 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright 2014 SUSE, LLC | ||
|
||
require "yast" | ||
|
||
module Yast | ||
# A drop-in replacement of an earlier Perl implementation | ||
class URLRecodeClass < Module | ||
# Escape password, user name and fragment part of URL string | ||
# @param [String] input input string | ||
# @return [String] Escaped string | ||
def EscapePassword(input) | ||
escape(input, USERNAME_PASSWORD_FRAGMENT_SAFE_CHARS) | ||
end | ||
|
||
# Escape path part of URL string | ||
# @param [String] input input string | ||
# @return [String] Escaped string | ||
def EscapePath(input) | ||
escape(input, PATH_SAFE_CHARS) | ||
end | ||
|
||
# Escape path part of URL string | ||
# @param [String] input input string | ||
# @return [String] Escaped string | ||
def EscapeQuery(input) | ||
escape(input, QUERY_SAFE_CHARS) | ||
end | ||
|
||
# UnEscape an URL string, replace %<Hexnum><HexNum> sequences | ||
# by character | ||
# @param [String] input input string | ||
# @return [String] Unescaped string | ||
def UnEscape(input) | ||
input.gsub(/%([0-9A-Fa-f]{2})/) { $1.to_i(16).chr }.force_encoding(input.encoding) | ||
end | ||
|
||
private | ||
|
||
# these will be substituted to a regex character class | ||
USERNAME_PASSWORD_FRAGMENT_SAFE_CHARS = "-A-Za-z0-9_.!~*'()" | ||
PATH_SAFE_CHARS = "-A-Za-z0-9_.!~*'()/" | ||
QUERY_SAFE_CHARS = "-A-Za-z0-9_.!~*'()/:=&" | ||
|
||
def escape(input, safe_chars) | ||
return nil if input.nil? | ||
input.gsub(/[^#{safe_chars}]/) do |unicode_char| | ||
escaped = "" | ||
unicode_char.each_byte {|b| escaped << sprintf("%%%02x", b) } | ||
escaped | ||
end | ||
end | ||
|
||
publish :function => :EscapePassword, :type => "string (string)" | ||
publish :function => :EscapePath, :type => "string (string)" | ||
publish :function => :EscapeQuery, :type => "string (string)" | ||
publish :function => :UnEscape, :type => "string (string)" | ||
end | ||
|
||
URLRecode = URLRecodeClass.new | ||
end |