Decode Numeric HTML Entities in ColdFusion?

前端 未结 4 1428
花落未央
花落未央 2020-12-06 12:15

I need a way to transform numeric HTML entities into their plain-text character equivalent. For example, I would like to turn the entity:

é
         


        
4条回答
  •  心在旅途
    2020-12-06 12:37

    I found this question while working with a method that, by black-box principle, can't trust that an incoming string is either HTML entity encoded or that it is not.

    I've adapted Peter Boughton's function so that it can be used safely on strings that haven't already been treated with HTML entities. (The only time this seems to matter is when loose ampersands - i.e. "Cats & Dogs" - are present in the target string.) This modified version will also fail somewhat gracefully on any unforseen XML parse error.

    
        
        
        
    
        
        
    
        
            
            
            
                
            
        
    
    

    This would support the following use case safely:

    
        
        
            Some Web User Spoke Thus:
    #HTMLEditFormat(decodeHTMLEntity(arguments.str))#

    This function is now incredibly useful for ensuring web-submitted content is entity-safe (think XSS) before it's sent out by email or submitted into a database table.

    Hope this helps.

提交回复
热议问题