mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-11-03 19:07:00 -05:00 
			
		
		
		
	Merge pull request #955 from barrycarey/issue-929-html-char-parsing
Ability to decode HTML Entities when all tags are stripped. Fixes #929
This commit is contained in:
		
						commit
						8cd7de25ad
					
				
							
								
								
									
										2235
									
								
								server/utils/htmlEntities.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2235
									
								
								server/utils/htmlEntities.js
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -1,4 +1,5 @@
 | 
			
		||||
const sanitizeHtml = require('../libs/sanitizeHtml')
 | 
			
		||||
const {entities} = require("./htmlEntities");
 | 
			
		||||
 | 
			
		||||
function sanitize(html) {
 | 
			
		||||
  const sanitizerOptions = {
 | 
			
		||||
@ -17,12 +18,22 @@ function sanitize(html) {
 | 
			
		||||
}
 | 
			
		||||
module.exports.sanitize = sanitize
 | 
			
		||||
 | 
			
		||||
function stripAllTags(html) {
 | 
			
		||||
function stripAllTags(html, shouldDecodeEntities = true) {
 | 
			
		||||
  const sanitizerOptions = {
 | 
			
		||||
    allowedTags: [],
 | 
			
		||||
    disallowedTagsMode: 'discard'
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return sanitizeHtml(html, sanitizerOptions)
 | 
			
		||||
  let sanitized = sanitizeHtml(html, sanitizerOptions)
 | 
			
		||||
  return shouldDecodeEntities ? decodeHTMLEntities(sanitized) : sanitized
 | 
			
		||||
}
 | 
			
		||||
module.exports.stripAllTags = stripAllTags
 | 
			
		||||
 | 
			
		||||
function decodeHTMLEntities(strToDecode) {
 | 
			
		||||
  return strToDecode.replace(/\&([^;]+);?/g, function (entity) {
 | 
			
		||||
    if (entity in entities) {
 | 
			
		||||
      return entities[entity]
 | 
			
		||||
    }
 | 
			
		||||
    return entity;
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user