mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	Merge pull request #3480 from contributor/feature/pageUrlSanitizeUrl
Fix pageUrl and clipping selection can create multiple notes for the same Url
This commit is contained in:
		
							
								
								
									
										11
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										11
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @@ -10,6 +10,7 @@ | ||||
|       "hasInstallScript": true, | ||||
|       "license": "AGPL-3.0-only", | ||||
|       "dependencies": { | ||||
|         "@braintree/sanitize-url": "^6.0.2", | ||||
|         "@electron/remote": "2.0.9", | ||||
|         "@excalidraw/excalidraw": "0.13.0", | ||||
|         "archiver": "5.3.1", | ||||
| @@ -115,6 +116,11 @@ | ||||
|         "node": ">=6.9.0" | ||||
|       } | ||||
|     }, | ||||
|     "node_modules/@braintree/sanitize-url": { | ||||
|       "version": "6.0.2", | ||||
|       "resolved": "https://registry.npmjs.org/@braintree/sanitize-url/-/sanitize-url-6.0.2.tgz", | ||||
|       "integrity": "sha512-Tbsj02wXCbqGmzdnXNk0SOF19ChhRU70BsroIi4Pm6Ehp56in6vch94mfbdQ17DozxkL3BAVjbZ4Qc1a0HFRAg==" | ||||
|     }, | ||||
|     "node_modules/@develar/schema-utils": { | ||||
|       "version": "2.6.5", | ||||
|       "resolved": "https://registry.npmjs.org/@develar/schema-utils/-/schema-utils-2.6.5.tgz", | ||||
| @@ -10552,6 +10558,11 @@ | ||||
|         "regenerator-runtime": "^0.13.4" | ||||
|       } | ||||
|     }, | ||||
|     "@braintree/sanitize-url": { | ||||
|       "version": "6.0.2", | ||||
|       "resolved": "https://registry.npmjs.org/@braintree/sanitize-url/-/sanitize-url-6.0.2.tgz", | ||||
|       "integrity": "sha512-Tbsj02wXCbqGmzdnXNk0SOF19ChhRU70BsroIi4Pm6Ehp56in6vch94mfbdQ17DozxkL3BAVjbZ4Qc1a0HFRAg==" | ||||
|     }, | ||||
|     "@develar/schema-utils": { | ||||
|       "version": "2.6.5", | ||||
|       "resolved": "https://registry.npmjs.org/@develar/schema-utils/-/schema-utils-2.6.5.tgz", | ||||
|   | ||||
| @@ -29,6 +29,7 @@ | ||||
|     "postinstall": "rimraf ./node_modules/canvas" | ||||
|   }, | ||||
|   "dependencies": { | ||||
|     "@braintree/sanitize-url": "^6.0.2", | ||||
|     "@electron/remote": "2.0.9", | ||||
|     "@excalidraw/excalidraw": "0.13.0", | ||||
|     "archiver": "5.3.1", | ||||
|   | ||||
| @@ -14,8 +14,8 @@ const Attribute = require('../../becca/entities/attribute'); | ||||
| const htmlSanitizer = require('../../services/html_sanitizer'); | ||||
| const {formatAttrForSearch} = require("../../services/attribute_formatter"); | ||||
|  | ||||
| function findClippingNote(todayNote, pageUrl) { | ||||
|     const notes = todayNote.searchNotesInSubtree( | ||||
| function findClippingNote(clipperInboxNote, pageUrl) { | ||||
|     const notes = clipperInboxNote.searchNotesInSubtree( | ||||
|         formatAttrForSearch({ | ||||
|             type: 'label', | ||||
|             name: "pageUrl", | ||||
| @@ -47,6 +47,7 @@ function addClipping(req) { | ||||
|  | ||||
|     const clipperInbox = getClipperInboxNote(); | ||||
|  | ||||
|     pageUrl = htmlSanitizer.sanitizeUrl(pageUrl); | ||||
|     let clippingNote = findClippingNote(clipperInbox, pageUrl); | ||||
|  | ||||
|     if (!clippingNote) { | ||||
| @@ -57,8 +58,6 @@ function addClipping(req) { | ||||
|             type: 'text' | ||||
|         }).note; | ||||
|  | ||||
|         pageUrl = htmlSanitizer.sanitize(pageUrl); | ||||
|  | ||||
|         clippingNote.setLabel('clipType', 'clippings'); | ||||
|         clippingNote.setLabel('pageUrl', pageUrl); | ||||
|         clippingNote.setLabel('iconClass', 'bx bx-globe'); | ||||
| @@ -96,7 +95,7 @@ function createNote(req) { | ||||
|     note.setLabel('clipType', clipType); | ||||
|  | ||||
|     if (pageUrl) { | ||||
|         pageUrl = htmlSanitizer.sanitize(pageUrl); | ||||
|         pageUrl = htmlSanitizer.sanitizeUrl(pageUrl); | ||||
|  | ||||
|         note.setLabel('pageUrl', pageUrl); | ||||
|         note.setLabel('iconClass', 'bx bx-globe'); | ||||
|   | ||||
| @@ -1,4 +1,5 @@ | ||||
| const sanitizeHtml = require('sanitize-html'); | ||||
| const sanitizeUrl = require('@braintree/sanitize-url').sanitizeUrl; | ||||
|  | ||||
| // intended mainly as protection against XSS via import | ||||
| // secondarily it (partly) protects against "CSS takeover" | ||||
| @@ -50,5 +51,6 @@ function sanitize(dirtyHtml) { | ||||
| } | ||||
|  | ||||
| module.exports = { | ||||
|     sanitize | ||||
|     sanitize, | ||||
|     sanitizeUrl | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user