[Fix] Replaced random escaping of $

The `$` symbol is now escaped by replacing it with a static string.
This commit is contained in:
Felipe Lalanne
2012-06-11 20:18:22 +02:00
parent 294a8e9642
commit f9cd97edaa
+3 -3
View File
@@ -125,13 +125,13 @@ module Gollum
# Returns the placeholder'd String data. # Returns the placeholder'd String data.
def extract_tex(data) def extract_tex(data)
# Random string to escape the `$` character (might be overkill) # Random string to escape the `$` character (might be overkill)
hash = "@#{rand(36**5).to_s(36)}@" esc = "/%%/"
data.gsub(/\\\[\s*(.*?)\s*\\\]/m) do data.gsub(/\\\[\s*(.*?)\s*\\\]/m) do
tag = CGI.escapeHTML($1) tag = CGI.escapeHTML($1)
id = Digest::SHA1.hexdigest(tag) id = Digest::SHA1.hexdigest(tag)
@texmap[id] = [:block, tag] @texmap[id] = [:block, tag]
id id
end.gsub(/'\$/, hash). # Replace `'$` by the hash generated earlier in order to escape it end.gsub(/'\$/, esc). # Replace `'$` with the `esc` string in order to escape it
gsub(/\$\$\s*(.*?)\s*\$\$/m) do gsub(/\$\$\s*(.*?)\s*\$\$/m) do
tag = CGI.escapeHTML($1) tag = CGI.escapeHTML($1)
id = Digest::SHA1.hexdigest(tag) id = Digest::SHA1.hexdigest(tag)
@@ -147,7 +147,7 @@ module Gollum
id = Digest::SHA1.hexdigest(tag) id = Digest::SHA1.hexdigest(tag)
@texmap[id] = [:inline, tag] @texmap[id] = [:inline, tag]
id id
end.gsub(/#{hash}/, '$') # replace the hash back to `$` end.gsub(/#{esc}/, '$') # replace the `esc` string back to `$`
end end
# Process all TeX from the texmap and replace the placeholders with the # Process all TeX from the texmap and replace the placeholders with the