Changeset 4119

Show
Ignore:
Timestamp:
01/25/09 14:14:29 (4 years ago)
Author:
jow
Message:

Merge r4115 r4118

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • luci/branches/luci-0.8/libs/core/luasrc/util.lua

    r3941 r4119  
    194194-- @param value String value containing the data to escape 
    195195-- @return      String value containing the escaped data 
    196 local _pcdata_repl = { 
    197                 ["&"] = "&", 
    198                 ['"'] = """, 
    199                 ["'"] = "'", 
    200                 ["<"] = "&#60;", 
    201                 [">"] = "&#62;" 
    202 } 
     196local function _pcdata_repl(c) 
     197    local i = string.byte(c) 
     198 
     199    if ( i >= 0x00 and i <= 0x08 ) or ( i >= 0x0B and i <= 0x0C ) or 
     200       ( i >= 0x0E and i <= 0x1F ) or ( i == 0x7F ) 
     201    then 
     202        return "" 
     203         
     204    elseif ( i == 0x26 ) or ( i == 0x27 ) or ( i == 0x22 ) or 
     205           ( i == 0x3C ) or ( i == 0x3E ) 
     206    then 
     207        return string.format("&#%i;", i) 
     208    end 
     209 
     210    return c 
     211end 
    203212 
    204213function pcdata(value) 
    205     return value and tostring(value):gsub("[&\"'<>]", _pcdata_repl) 
     214    return value and tostring(value):gsub("[&\"'<>%c]", _pcdata_repl) 
    206215end 
    207216