mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 13:01:31 +08:00 
			
		
		
		
	Merge pull request #2117 from TriliumNext/external_links
fix(link): Allow external links containing # to open
This commit is contained in:
		
						commit
						aa6ad0b619
					
				| @ -16,4 +16,24 @@ describe("Link", () => { | |||||||
|         const output = parseNavigationStateFromUrl(`#root/WWaBNf3SSA1b/mQ2tIzLVFKHL`); |         const output = parseNavigationStateFromUrl(`#root/WWaBNf3SSA1b/mQ2tIzLVFKHL`); | ||||||
|         expect(output).toMatchObject({ notePath: "root/WWaBNf3SSA1b/mQ2tIzLVFKHL", noteId: "mQ2tIzLVFKHL" }); |         expect(output).toMatchObject({ notePath: "root/WWaBNf3SSA1b/mQ2tIzLVFKHL", noteId: "mQ2tIzLVFKHL" }); | ||||||
|     }); |     }); | ||||||
|  | 
 | ||||||
|  |     it("parses notePath with spaces", () => { | ||||||
|  |         const output = parseNavigationStateFromUrl(`  #root/WWaBNf3SSA1b/mQ2tIzLVFKHL`); | ||||||
|  |         expect(output).toMatchObject({ notePath: "root/WWaBNf3SSA1b/mQ2tIzLVFKHL", noteId: "mQ2tIzLVFKHL" }); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     it("ignores external URL with internal hash anchor", () => { | ||||||
|  |         const output = parseNavigationStateFromUrl(`https://en.wikipedia.org/wiki/Bearded_Collie#Health`); | ||||||
|  |         expect(output).toMatchObject({}); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     it("ignores malformed but hash-containing external URL", () => { | ||||||
|  |         const output = parseNavigationStateFromUrl("https://abc.com/#drop?searchString=firefox"); | ||||||
|  |         expect(output).toStrictEqual({}); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     it("ignores non-hash internal path", () => { | ||||||
|  |         const output = parseNavigationStateFromUrl("/root/abc123"); | ||||||
|  |         expect(output).toStrictEqual({}); | ||||||
|  |     }); | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -204,11 +204,17 @@ export function parseNavigationStateFromUrl(url: string | undefined) { | |||||||
|         return {}; |         return {}; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     url = url.trim(); | ||||||
|     const hashIdx = url.indexOf("#"); |     const hashIdx = url.indexOf("#"); | ||||||
|     if (hashIdx === -1) { |     if (hashIdx === -1) { | ||||||
|         return {}; |         return {}; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     // Exclude external links that contain #
 | ||||||
|  |     if (hashIdx !== 0 && !url.includes("/#root") && !url.includes("/#?searchString")) {  | ||||||
|  |         return {}; | ||||||
|  |     } | ||||||
|  |      | ||||||
|     const hash = url.substr(hashIdx + 1); // strip also the initial '#'
 |     const hash = url.substr(hashIdx + 1); // strip also the initial '#'
 | ||||||
|     let [notePath, paramString] = hash.split("?"); |     let [notePath, paramString] = hash.split("?"); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Elian Doran
						Elian Doran