提交 1f6815a8 编写于 作者: M Martin Aeschlimann

[html] get all link tests to run

上级 8d7504f7
...@@ -18,7 +18,7 @@ function _stripQuotes(url: string): string { ...@@ -18,7 +18,7 @@ function _stripQuotes(url: string): string {
.replace(/^"([^"]+)"$/,(substr, match1) => match1); .replace(/^"([^"]+)"$/,(substr, match1) => match1);
} }
export function _getWorkspaceUrl(modelAbsoluteUri: Uri, rootAbsoluteUrlStr: string, tokenContent: string): string { export function _getWorkspaceUrl(modelAbsoluteUri: Uri, rootAbsoluteUrl: Uri, tokenContent: string): string {
tokenContent = _stripQuotes(tokenContent); tokenContent = _stripQuotes(tokenContent);
if (/^\s*javascript\:/i.test(tokenContent) || /^\s*\#/i.test(tokenContent)) { if (/^\s*javascript\:/i.test(tokenContent) || /^\s*\#/i.test(tokenContent)) {
...@@ -47,9 +47,10 @@ export function _getWorkspaceUrl(modelAbsoluteUri: Uri, rootAbsoluteUrlStr: stri ...@@ -47,9 +47,10 @@ export function _getWorkspaceUrl(modelAbsoluteUri: Uri, rootAbsoluteUrlStr: stri
alternativeResultPath = paths.join(modelPath, tokenContent); alternativeResultPath = paths.join(modelPath, tokenContent);
alternativeResultPath = alternativeResultPath.replace(/^(\/\.\.)+/, ''); alternativeResultPath = alternativeResultPath.replace(/^(\/\.\.)+/, '');
} }
let potentialResult = modelAbsoluteUri.with({ path: alternativeResultPath }).toString(); let potentialResult = modelAbsoluteUri.with({ path: alternativeResultPath }).toString(true);
if (rootAbsoluteUrlStr && strings.startsWith(modelAbsoluteUri.toString(), rootAbsoluteUrlStr)) { let rootAbsoluteUrlStr = rootAbsoluteUrl && rootAbsoluteUrl.toString(true);
if (rootAbsoluteUrlStr && strings.startsWith(modelAbsoluteUri.toString(true), rootAbsoluteUrlStr)) {
// The `rootAbsoluteUrl` is set and matches our current model // The `rootAbsoluteUrl` is set and matches our current model
// We need to ensure that this `potentialResult` does not escape `rootAbsoluteUrl` // We need to ensure that this `potentialResult` does not escape `rootAbsoluteUrl`
...@@ -63,7 +64,7 @@ export function _getWorkspaceUrl(modelAbsoluteUri: Uri, rootAbsoluteUrlStr: stri ...@@ -63,7 +64,7 @@ export function _getWorkspaceUrl(modelAbsoluteUri: Uri, rootAbsoluteUrlStr: stri
return potentialResult; return potentialResult;
} }
function createLink(document: TextDocument, rootAbsoluteUrl: string, tokenContent: string, startOffset: number, endOffset: number): DocumentLink { function createLink(document: TextDocument, rootAbsoluteUrl: Uri, tokenContent: string, startOffset: number, endOffset: number): DocumentLink {
let documentUri = Uri.parse(document.uri); let documentUri = Uri.parse(document.uri);
let workspaceUrl = _getWorkspaceUrl(documentUri, rootAbsoluteUrl, tokenContent); let workspaceUrl = _getWorkspaceUrl(documentUri, rootAbsoluteUrl, tokenContent);
if (!workspaceUrl) { if (!workspaceUrl) {
...@@ -78,15 +79,13 @@ function createLink(document: TextDocument, rootAbsoluteUrl: string, tokenConten ...@@ -78,15 +79,13 @@ function createLink(document: TextDocument, rootAbsoluteUrl: string, tokenConten
export function provideLinks(document: TextDocument, workspacePath:string): DocumentLink[] { export function provideLinks(document: TextDocument, workspacePath:string): DocumentLink[] {
let newLinks: DocumentLink[] = []; let newLinks: DocumentLink[] = [];
let rootAbsoluteUrl: string = null; let rootAbsoluteUrl: Uri = null;
if (workspacePath) { if (workspacePath) {
// The workspace can be null in the no folder opened case // The workspace can be null in the no folder opened case
let strRootAbsoluteUrl = workspacePath; if (workspacePath.charAt(workspacePath.length - 1) !== '/') {
if (strRootAbsoluteUrl.charAt(strRootAbsoluteUrl.length - 1) === '/') { workspacePath = workspacePath + '/';
rootAbsoluteUrl = strRootAbsoluteUrl;
} else {
rootAbsoluteUrl = strRootAbsoluteUrl + '/';
} }
rootAbsoluteUrl = Uri.parse(workspacePath);
} }
let scanner = createScanner(document.getText(), 0); let scanner = createScanner(document.getText(), 0);
......
...@@ -14,7 +14,7 @@ suite('HTML Link Detection', () => { ...@@ -14,7 +14,7 @@ suite('HTML Link Detection', () => {
function testLinkCreation(modelUrl:string, rootUrl:string, tokenContent:string, expected:string): void { function testLinkCreation(modelUrl:string, rootUrl:string, tokenContent:string, expected:string): void {
var _modelUrl = Uri.parse(modelUrl); var _modelUrl = Uri.parse(modelUrl);
var actual = htmlLinks._getWorkspaceUrl(_modelUrl, rootUrl, tokenContent); var actual = htmlLinks._getWorkspaceUrl(_modelUrl, Uri.parse(rootUrl), tokenContent);
assert.equal(actual, expected); assert.equal(actual, expected);
} }
...@@ -44,7 +44,7 @@ suite('HTML Link Detection', () => { ...@@ -44,7 +44,7 @@ suite('HTML Link Detection', () => {
testLinkCreation('file:///C:/Alex/src/path/to/file.txt', null, 'http://www.microsoft.com/', 'http://www.microsoft.com/'); testLinkCreation('file:///C:/Alex/src/path/to/file.txt', null, 'http://www.microsoft.com/', 'http://www.microsoft.com/');
testLinkCreation('file:///C:/Alex/src/path/to/file.txt', null, 'https://www.microsoft.com/', 'https://www.microsoft.com/'); testLinkCreation('file:///C:/Alex/src/path/to/file.txt', null, 'https://www.microsoft.com/', 'https://www.microsoft.com/');
testLinkCreation('file:///C:/Alex/src/path/to/file.txt', null, ' //www.microsoft.com/', 'http://www.microsoft.com/'); testLinkCreation('file:///C:/Alex/src/path/to/file.txt', null, ' //www.microsoft.com/', 'http://www.microsoft.com/');
//testLinkCreation('file:///C:/Alex/src/path/to/file.txt', null, 'a.js', 'file:///C:/Alex/src/path/to/a.js'); testLinkCreation('file:///C:/Alex/src/path/to/file.txt', null, 'a.js', 'file:///c:/Alex/src/path/to/a.js');
testLinkCreation('file:///C:/Alex/src/path/to/file.txt', null, '/a.js', 'file:///a.js'); testLinkCreation('file:///C:/Alex/src/path/to/file.txt', null, '/a.js', 'file:///a.js');
testLinkCreation('file:///C:/Alex/src/path/to/file.txt', 'file:///C:/Alex/src/', 'javascript:void;', null); testLinkCreation('file:///C:/Alex/src/path/to/file.txt', 'file:///C:/Alex/src/', 'javascript:void;', null);
...@@ -55,17 +55,17 @@ suite('HTML Link Detection', () => { ...@@ -55,17 +55,17 @@ suite('HTML Link Detection', () => {
testLinkCreation('file:///C:/Alex/src/path/to/file.txt', 'file:///C:/Alex/src/', 'https://www.microsoft.com/', 'https://www.microsoft.com/'); testLinkCreation('file:///C:/Alex/src/path/to/file.txt', 'file:///C:/Alex/src/', 'https://www.microsoft.com/', 'https://www.microsoft.com/');
testLinkCreation('file:///C:/Alex/src/path/to/file.txt', 'file:///C:/Alex/src/', 'https://www.microsoft.com/?q=1#h', 'https://www.microsoft.com/?q=1#h'); testLinkCreation('file:///C:/Alex/src/path/to/file.txt', 'file:///C:/Alex/src/', 'https://www.microsoft.com/?q=1#h', 'https://www.microsoft.com/?q=1#h');
testLinkCreation('file:///C:/Alex/src/path/to/file.txt', 'file:///C:/Alex/src/', ' //www.microsoft.com/', 'http://www.microsoft.com/'); testLinkCreation('file:///C:/Alex/src/path/to/file.txt', 'file:///C:/Alex/src/', ' //www.microsoft.com/', 'http://www.microsoft.com/');
//testLinkCreation('file:///C:/Alex/src/path/to/file.txt', 'file:///C:/Alex/src/', 'a.js', 'file:///C:/Alex/src/path/to/a.js'); testLinkCreation('file:///C:/Alex/src/path/to/file.txt', 'file:///C:/Alex/src/', 'a.js', 'file:///c:/Alex/src/path/to/a.js');
//testLinkCreation('file:///C:/Alex/src/path/to/file.txt', 'file:///C:/Alex/src/', '/a.js', 'file:///C:/Alex/src/a.js'); testLinkCreation('file:///C:/Alex/src/path/to/file.txt', 'file:///C:/Alex/src/', '/a.js', 'file:///c:/Alex/src/a.js');
testLinkCreation('https://www.test.com/path/to/file.txt', null, 'file:///C:\\Alex\\src\\path\\to\\file.txt', 'file:///C:\\Alex\\src\\path\\to\\file.txt'); testLinkCreation('https://www.test.com/path/to/file.txt', null, 'file:///C:\\Alex\\src\\path\\to\\file.txt', 'file:///C:\\Alex\\src\\path\\to\\file.txt');
testLinkCreation('https://www.test.com/path/to/file.txt', null, '//www.microsoft.com/', 'https://www.microsoft.com/'); testLinkCreation('https://www.test.com/path/to/file.txt', null, '//www.microsoft.com/', 'https://www.microsoft.com/');
testLinkCreation('https://www.test.com/path/to/file.txt', 'https://www.test.com', '//www.microsoft.com/', 'https://www.microsoft.com/'); testLinkCreation('https://www.test.com/path/to/file.txt', 'https://www.test.com', '//www.microsoft.com/', 'https://www.microsoft.com/');
// invalid uris don't throw // invalid uris don't throw
testLinkCreation('https://www.test.com/path/to/file.txt', 'https://www.test.com', '%', 'https://www.test.com/path/to/%25'); testLinkCreation('https://www.test.com/path/to/file.txt', 'https://www.test.com', '%', 'https://www.test.com/path/to/%');
// Bug #18314: Ctrl + Click does not open existing file if folder's name starts with 'c' character // Bug #18314: Ctrl + Click does not open existing file if folder's name starts with 'c' character
// testLinkCreation('file:///c:/Alex/working_dir/18314-link-detection/test.html', 'file:///c:/Alex/working_dir/18314-link-detection/', '/class/class.js', 'file:///c:/Alex/working_dir/18314-link-detection/class/class.js'); testLinkCreation('file:///c:/Alex/working_dir/18314-link-detection/test.html', 'file:///c:/Alex/working_dir/18314-link-detection/', '/class/class.js', 'file:///c:/Alex/working_dir/18314-link-detection/class/class.js');
}); });
}); });
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册