Fix URL lexer dropping the host and path when a port is present#3739
Open
chatman-media wants to merge 1 commit into
Open
Fix URL lexer dropping the host and path when a port is present#3739chatman-media wants to merge 1 commit into
chatman-media wants to merge 1 commit into
Conversation
When a URL had an explicit port (http://localhost:8080/api), lex_hostport scanned for the end of the port starting from the beginning of the host instead of after the colon. The host's first character is a letter (or the scan stops at the first dot), so the search for the first non-digit returned almost immediately and the port was treated as zero-length. The URL token then ended right after the scheme, leaving the host, port, and path to be tokenized as ordinary prose and spell-checked. Scan the port digits from just after the colon, and leave the colon unconsumed when no digits follow it.
Collaborator
|
Yes I've made some toy projects recently annotated text tokenized by Harper, and sometimes whole URLs are interpreted as a single URL token and sometimes only the host is interpreted as a host token and all the other parts are interpreted as words and punctuation. But I haven't yet figured out the pattern or whether it's plain text input vs Markdown input. I don't think the ones I encountered used the port, so I suspect there's more than one problem in our URL parsing. |
Collaborator
|
@chatman-media, have you read our agent policy? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
URLs with an explicit port lose everything after the scheme.
http://localhost:8080/apigets tokenized with onlyhttp://as the URL, andlocalhost:8080/apiends up treated as ordinary text (so the host and path get spell-checked).The cause is in
lex_hostport: when a:follows the host, it looks for the end of the port by scanning for the first non-digit from the start of the host rather than from after the colon. Since the host starts with a letter (or the scan stops at the first dot), that search returns almost immediately and the port comes out zero-length, ending the URL right after the scheme.This scans the port digits from just after the colon, and leaves the colon alone if there's no port behind it. Added a few cases to the url tests (
localhost:8080, with a path, and an IP with a port).