add HTML entity de- and encoding
This commit is contained in:
		
							parent
							
								
									e6de88ef31
								
							
						
					
					
						commit
						feb7939488
					
				
					 1 changed files with 43 additions and 8 deletions
				
			
		
							
								
								
									
										51
									
								
								dencode.js
									
										
									
									
									
								
							
							
						
						
									
										51
									
								
								dencode.js
									
										
									
									
									
								
							|  | @ -3,7 +3,7 @@ | ||||||
| 		{ | 		{ | ||||||
| 			"id": "CHOOSE", | 			"id": "CHOOSE", | ||||||
| 			"name": "Please choose your conversion ...", | 			"name": "Please choose your conversion ...", | ||||||
| 			"convert": function(input) { | 			"convert": function (input) { | ||||||
| 				return { | 				return { | ||||||
| 					"status": "OK", | 					"status": "OK", | ||||||
| 					"content": "" | 					"content": "" | ||||||
|  | @ -13,7 +13,7 @@ | ||||||
| 		{ | 		{ | ||||||
| 			"id": "base64encode", | 			"id": "base64encode", | ||||||
| 			"name": "Base64 encode", | 			"name": "Base64 encode", | ||||||
| 			"convert": function(input) { | 			"convert": function (input) { | ||||||
| 				return { | 				return { | ||||||
| 					"status": "OK", | 					"status": "OK", | ||||||
| 					"content": btoa(input) | 					"content": btoa(input) | ||||||
|  | @ -23,7 +23,7 @@ | ||||||
| 		{ | 		{ | ||||||
| 			"id": "base64decode", | 			"id": "base64decode", | ||||||
| 			"name": "Base64 decode", | 			"name": "Base64 decode", | ||||||
| 			"convert": function(input) { | 			"convert": function (input) { | ||||||
| 				try { | 				try { | ||||||
| 					return { | 					return { | ||||||
| 						"status": "OK", | 						"status": "OK", | ||||||
|  | @ -40,7 +40,7 @@ | ||||||
| 		{ | 		{ | ||||||
| 			"id": "encodeuri", | 			"id": "encodeuri", | ||||||
| 			"name": "Encode URI", | 			"name": "Encode URI", | ||||||
| 			"convert": function(input) { | 			"convert": function (input) { | ||||||
| 				return { | 				return { | ||||||
| 					"status": "OK", | 					"status": "OK", | ||||||
| 					"content": encodeURI(input).replace(/%5B/g, '[').replace(/%5D/g, ']') | 					"content": encodeURI(input).replace(/%5B/g, '[').replace(/%5D/g, ']') | ||||||
|  | @ -50,7 +50,7 @@ | ||||||
| 		{ | 		{ | ||||||
| 			"id": "decodeuri", | 			"id": "decodeuri", | ||||||
| 			"name": "Decode URI", | 			"name": "Decode URI", | ||||||
| 			"convert": function(input) { | 			"convert": function (input) { | ||||||
| 				try { | 				try { | ||||||
| 					return { | 					return { | ||||||
| 						"status": "OK", | 						"status": "OK", | ||||||
|  | @ -67,7 +67,7 @@ | ||||||
| 		{ | 		{ | ||||||
| 			"id": "encodeuricomponent", | 			"id": "encodeuricomponent", | ||||||
| 			"name": "Encode URI component", | 			"name": "Encode URI component", | ||||||
| 			"convert": function(input) { | 			"convert": function (input) { | ||||||
| 				return { | 				return { | ||||||
| 					"status": "OK", | 					"status": "OK", | ||||||
| 					"content": encodeURIComponent(input).replace(/[!'()*]/g, function(c) { | 					"content": encodeURIComponent(input).replace(/[!'()*]/g, function(c) { | ||||||
|  | @ -79,7 +79,7 @@ | ||||||
| 		{ | 		{ | ||||||
| 			"id": "decodeuricomponent", | 			"id": "decodeuricomponent", | ||||||
| 			"name": "Decode URI component", | 			"name": "Decode URI component", | ||||||
| 			"convert": function(input) { | 			"convert": function (input) { | ||||||
| 				try { | 				try { | ||||||
| 					return { | 					return { | ||||||
| 						"status": "OK", | 						"status": "OK", | ||||||
|  | @ -92,6 +92,41 @@ | ||||||
| 					}; | 					}; | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			"id": "encodehtmlentities", | ||||||
|  | 			"name": "Encode HTML entities", | ||||||
|  | 			"convert": function (input) { | ||||||
|  | 				return { | ||||||
|  | 					"status": "OK", | ||||||
|  | 					"content": input | ||||||
|  | 						.replace(/\&/g, "&") | ||||||
|  | 						.replace(/\</g, "<") | ||||||
|  | 						.replace(/\>/g, ">") | ||||||
|  | 						.replace(/\"/g, """) | ||||||
|  | 				}; | ||||||
|  | 			} | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			"id": "decodehtmlentities", | ||||||
|  | 			"name": "Decode HTML entities", | ||||||
|  | 			"convert": function (input) { | ||||||
|  | 				try { | ||||||
|  | 					return { | ||||||
|  | 						"status": "OK", | ||||||
|  | 						"content": input | ||||||
|  | 							.replace(/\"\;/g, "\"") | ||||||
|  | 							.replace(/\>\;/g, ">") | ||||||
|  | 							.replace(/\<\;/g, "<") | ||||||
|  | 							.replace(/\&\;/g, "&") | ||||||
|  | 					}; | ||||||
|  | 				} catch (exception) { | ||||||
|  | 					return { | ||||||
|  | 						"status": "ERROR", | ||||||
|  | 						"content": "Invalid HTML entity string." | ||||||
|  | 					}; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	]; | 	]; | ||||||
| 
 | 
 | ||||||
|  | @ -151,7 +186,7 @@ | ||||||
| 		} | 		} | ||||||
| 		if (appendNewOutput) { | 		if (appendNewOutput) { | ||||||
| 			if (output !== "") { | 			if (output !== "") { | ||||||
| 				$output = $(template.replace(/\{index\}/g, "" + outputIndex).replace(/\{content\}/g, output)); | 				$output = $(template.replace(/\{index\}/g, "" + outputIndex).replace(/\{content\}/g, output.replace(/\&/g, "&"))); | ||||||
| 				if (status === "ERROR") { | 				if (status === "ERROR") { | ||||||
| 					$output.find("textarea").addClass("error"); | 					$output.find("textarea").addClass("error"); | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue