fix Redirect

This commit is contained in:
Sidharth Vinod
2022-12-19 13:51:05 +05:30
parent 8e7dd1d148
commit fd5780d5a1
2 changed files with 4 additions and 7 deletions

View File

@@ -8,6 +8,7 @@ test.each([
['http://localhost:1234/mermaid/#/flowchart.md', 'syntax/flowchart.html'], ['http://localhost:1234/mermaid/#/flowchart.md', 'syntax/flowchart.html'],
['http://localhost/mermaid/#/flowchart.md', 'syntax/flowchart.html'], ['http://localhost/mermaid/#/flowchart.md', 'syntax/flowchart.html'],
['https://mermaid-js.github.io/mermaid/#/flowchart.md', 'syntax/flowchart.html'], ['https://mermaid-js.github.io/mermaid/#/flowchart.md', 'syntax/flowchart.html'],
['https://mermaid.js.org/#/flowchart.md', 'syntax/flowchart.html'],
['https://mermaid-js.github.io/mermaid/#/./flowchart', 'syntax/flowchart.html'], ['https://mermaid-js.github.io/mermaid/#/./flowchart', 'syntax/flowchart.html'],
['https://mermaid-js.github.io/mermaid/#/flowchart', 'syntax/flowchart.html'], ['https://mermaid-js.github.io/mermaid/#/flowchart', 'syntax/flowchart.html'],
['https://mermaid-js.github.io/mermaid/#flowchart', 'syntax/flowchart.html'], ['https://mermaid-js.github.io/mermaid/#flowchart', 'syntax/flowchart.html'],
@@ -31,7 +32,4 @@ test.each([
test('should throw for invalid URL', () => { test('should throw for invalid URL', () => {
// Not mermaid domain // Not mermaid domain
expect(() => getRedirect('https://www.google.com')).toThrowError(); expect(() => getRedirect('https://www.google.com')).toThrowError();
// Not `/mermaid/` path
expect(() => getRedirect('http://localhost/#/flowchart.md')).toThrowError();
}); });

View File

@@ -10,10 +10,9 @@ export interface Redirect {
const getBaseFile = (link: string): Redirect => { const getBaseFile = (link: string): Redirect => {
const url = new URL(link); const url = new URL(link);
if ( if (
(url.hostname !== 'mermaid-js.github.io' && url.hostname !== 'mermaid-js.github.io' &&
url.hostname !== 'mermaid.js.org' && url.hostname !== 'mermaid.js.org' &&
url.hostname !== 'localhost') || url.hostname !== 'localhost'
url.pathname !== '/mermaid/'
) { ) {
throw new Error('Not mermaidjs url'); throw new Error('Not mermaidjs url');
} }