JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
html serialization: implement attr encoding
authorJason Woofenden <jason@jasonwoof.com>
Sat, 23 Jan 2016 19:09:53 +0000 (14:09 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Sat, 23 Jan 2016 19:09:53 +0000 (14:09 -0500)
editor.coffee

index b608e6b..c01a2b1 100644 (file)
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # encode text so it can be safely placed inside an html attribute
+enc_attr_regex = new RegExp '(&)|(")|(\u00A0)', 'g'
 enc_attr = (txt) ->
-       # FIXME implement
-       return txt
+       return txt.replace enc_attr_regex, (match, amp, quote) ->
+               return '&amp;' if (amp)
+               return '&quot;' if (quote)
+               return '&nbsp;'
 
 void_elements = {
        area: true