module HWSStrings # These constants are used as the default configuration for the # component_encode and component_decode methods. GF_CHARACTER_MAPPING = { '/' => '_0xS_', ':' => '_0xC_', } GF_DEFAULT_ILLEGAL_CHARS = GF_CHARACTER_MAPPING.keys URI_ILLEGAL_CHARACTERS = ['/', '\\', ':', '?', '=', '%'] DEFAULT_ILLEGAL_CHARS = ['~', '/', ' '] DEFAULT_ESCAPE = '~' # Encode the string to make it usable as a single path in a URL. # # This a simple scheme that should allow you to match the string in a single # path variable easily, in a way that should not be messed with by your # web framework. # # Many characters that are legal as file names by the Helix Versioning Engine # can make URL handling difficult. The most basic is the forward slash '/'. # # This does *NOT* guarantee that the string is URL safe! You should still # percent-encode any string as a URL. def self.component_encode(str, illegal_characters: DEFAULT_ILLEGAL_CHARS) str.chars.map do |ch| if illegal_characters.include?(ch) '~' + ch.ord.to_s(16) else ch end end.join('') end # Decodes a string encoded with component_encode. def self.component_decode(str, escape = DEFAULT_ESCAPE, illegal_characters = DEFAULT_ILLEGAL_CHARS) escape_map = Hash[illegal_characters.map{ |c| [c, "#{escape}#{c.ord.to_s(16)}"] }] escape_map.each do |ch, escaped| str = str.gsub(escaped, ch) end str end # Encodes a string for Git Fusion use def self.gf_encode(str, illegal_characters: GF_DEFAULT_ILLEGAL_CHARS) str.chars.map do |ch| if illegal_characters.include?(ch) GF_CHARACTER_MAPPING[ch] else ch end end.join('') end # Decodes a string for Git Fusion use def self.gf_decode(str, illegal_characters: GF_DEFAULT_ILLEGAL_CHARS) escape_map = Hash[illegal_characters.map{ |c| [c, GF_CHARACTER_MAPPING[c]] }] escape_map.each do |ch, escaped| str = str.gsub(escaped, ch) end str end end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 15745 | ptomiak |
Second part of shelved changes. Contains updated git-fusion app, changes to string encodig/decoding and updated docs. |
||
#2 | 15744 | ptomiak | Unshelve files from review 15549 to my dev branch. | ||
#1 | 15741 | ptomiak | Branch HWS for my use. | ||
//guest/perforce_software/helix-web-services/main/source/helix_web_services/lib/hws_strings.rb | |||||
#1 | 15622 | tjuricek |
Move source code to 'source/' subdirectory of branch. build/ will remain where it is. |
||
//guest/perforce_software/helix-web-services/main/helix_web_services/lib/hws_strings.rb | |||||
#1 | 15542 | tjuricek |
Add spaces to our basic 'component encode' mechanism, and use it for HVE project IDs. In general, this will make the HVE IDs a bit more readable. |
||
//guest/perforce_software/helix-web-services/main/helix_web_services/lib/hws_urls.rb | |||||
#1 | 15532 | tjuricek | Add a basic HWSUrls class to handle strings with forward slashes as URL path parts. |