Ruby.Me.Silly
2007-Apr-08  05:32 UTC
Why would BlueCloth use an EscapeTable of MD5 hash values?
I was looking at the source code to BlueCloth and came across the
following lines of code:
# Table of MD5 sums for escaped characters
	EscapeTable = {}
	''\\`*_{}[]()#.!''.split(//).each {|char|
		hash = Digest::MD5::hexdigest( char )
		EscapeTable[ char ] = {
 			:md5 => hash,
			:md5re => Regexp::new( hash ),
			:re  => Regexp::new( ''\\\\'' + Regexp::escape(char) ),
		}
	}
One particular use of the EscapeTable is in this function:
### Escape special characters in the given +str+
	def escape_special_chars( str )
		@log.debug "  Escaping special characters"
		text = ''''
		# The original Markdown source has something called
''$tags_to_skip''
		# declared here, but it''s never used, so I don''t define it.
		tokenize_html( str ) {|token, str|
			@log.debug "   Adding %p token %p" % [ token, str ]
			case token
			# Within tags, encode * and _
			when :tag
				text += str.
					gsub( /\*/, EscapeTable[''*''][:md5] ).
					gsub( /_/, EscapeTable[''_''][:md5] )
			# Encode backslashed stuff in regular text
			when :text
				text += encode_backslash_escapes( str )
			else
				raise TypeError, "Unknown token type %p" % token
			end
		}
		@log.debug "  Text with escapes is now: %p" % text
		return text
	end
Now can someone please tell me why you would want to escape this
particular set of characters?  In addition, why use an md5 hash?  Why
not an entity character reference?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---