Skip to content

Conversation

@jrkong
Copy link
Contributor

@jrkong jrkong commented Oct 22, 2018

@Tyriar This PR should fix issue #60401 for VS Code downstream.

I updated the webLinks pathClause regex

const pathClause = '(\\/[\\/\\w\\.\\-%~]*)*';
to accept colons. So the new regex is now (\\/[\\/\\w\\.\\-%~:]*)*

I also updated the tests to test for the colon case in the path.

image

If there are any updates I should make please let me know.

@jrkong jrkong changed the title Updated webLinks regex to fix vscode issue#60401 Updated webLinks regex accept colons, fix vscode issue#60401 Oct 22, 2018
webLinks.webLinksInit(<any>term);

const row = ' http://foo.com/a~b#c~d?e~f ';
const row = ' http://foo.com/a~b#c~d?e~f: ';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to allow semi-colons except for the last character?

So this row:

const row = '  http://foo.com/a~b#c~d?e~:f:  ';

Resulted in this:

assert.equal(uri, 'http://foo.com/a~b#c~d?e~:f');

Copy link
Contributor Author

@jrkong jrkong Oct 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tyriar I've been testing it out and I don't think it's doable, at least not through regex. I can't think of a way to implement an exception case into the capture group so that it accepts all : except for the last character.

I was thinking of handling the case by processing the uri after it's processed by strictUrlRegex. Would that be a viable solution? If so how would I access the uri before it's returned? I couldn't to access it properly/safely during my tests.

If you have any other ideas on how to implement this please let me know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The concern is that then we will break on this type of link microsoft/vscode#50426 (comment) (I know it's a file not a URL but this just popped up in my inbox). It's hard to say which is more common 😕

Copy link
Contributor Author

@jrkong jrkong Oct 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that the only case we need to be concerned with as I don't think it will be an issue.

In VS Code the path regex is managed by these lines in terminalLinkHandler.ts in VS Code.

This results in the regex

/(((\.\.?|\~)|([^\0\s!$`&*()\[\]+'":;\\])+)?(\/([^\0\s!$`&*()\[\]+'":;\\])+)+)(((\S*)",[  ]line[  ]((\d+)([  ]column[  ](\d+))?))|((\S*)[  ]on[  ]line[  ]((\d+)(,[  ]column[  ](\d+))?))|((\S*):line[  ]((\d+)(,[  ]column[  ](\d+))?))|(([^\s\(\)]*)(\s?[\(\[](\d+)(,\s?(\d+))?)[\)\]])|(([^:\s\(\)<>'"\[\]]*)(:(\d+))?(:(\d+))?))/

in Javascript.
image

In comparison to

/(?:^|[^\da-z\.-]+)((https?:\/\/)((([\da-z\.-]+)\.([a-z\.]{2,6}))|((\d{1,3}\.){3}\d{1,3})|(localhost))(:\d{1,5})?(\/[\/\w\.\-%~]*)*(\?[0-9\w\[\]\(\)\/\?\!#@$%&'*+,:;~\=\.\-]*)?(#[0-9\w\[\]\(\)\/\?\!#@$%&'*+,:;~\=\.\-]*)?)($|[^\/\w\.\-%]+)/

which is used when a web link is detected.

image

Are there any other cases that this change could break?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean this form could appear in URLs as well though, for example:

https://go.microsoft.com/fwlink/?LinkId=blah: some description

Will a [^:\s]* similar to the path regex not work for webLinks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tyriar fixed! [^:\s] worked. I completely overlooked the \s character as I was doing my tests! Thanks for pointing that out! I've added tests as well to verify the functionality of both cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tyriar can you check if the PR is missing any edge cases or tests? Colons at the end of URLs are ignored now but I'm not sure if I'm missing anything else that needs to be accounted for.

Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about the delay. This was a little unexpected but other than that it looks like a great compromise:

screen shot 2018-11-18 at 2 09 16 pm

It seems to take all colons in the string if there are colons not at the end.

@Tyriar Tyriar added this to the 3.9.0 milestone Nov 18, 2018
@Tyriar Tyriar merged commit e4a8464 into xtermjs:master Nov 18, 2018
@jrkong jrkong deleted the vscode-issue-60401 branch November 19, 2018 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

URLs with : in them are not "clickable" in terminal

2 participants