[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to have a more accurate url error #3488

Merged
merged 7 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,17 @@ public HttpSyntaxTree Parse()
{
if (node is null)
{
if (CurrentToken is ({ Kind: HttpTokenKind.Word }) or ({ Kind: HttpTokenKind.Punctuation} and { Text: "/"}))
if (CurrentToken is ({ Kind: HttpTokenKind.Word }) or ({ Kind: HttpTokenKind.Punctuation } and { Text: "/" }))
{
node = new HttpVariableValueNode(_sourceText, _syntaxTree);

ParseLeadingWhitespaceAndComments(node);
}
}
else if (IsAtStartOfEmbeddedExpression())
{
node = new HttpVariableValueNode(_sourceText, _syntaxTree);
node.Add(ParseEmbeddedExpression());
if(CurrentToken is { Kind: HttpTokenKind.NewLine })
if (CurrentToken is { Kind: HttpTokenKind.NewLine })
{
break;
}
Expand Down Expand Up @@ -448,6 +448,10 @@ private void ConsumeCurrentTokenInto(HttpSyntaxNode node)
node = new HttpUrlNode(_sourceText, _syntaxTree);
node.Add(ParseEmbeddedExpression());
}
else if (CurrentToken is { Kind: HttpTokenKind.Punctuation })
shyamnamboodiripad marked this conversation as resolved.
Show resolved Hide resolved
shyamnamboodiripad marked this conversation as resolved.
Show resolved Hide resolved
{
node = new HttpUrlNode(_sourceText, _syntaxTree);
shyamnamboodiripad marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void multiple_punctuations_are_parsed_into_different_tokens()
{
var result = Parse(".!?.:/");

var requestNode = result.SyntaxTree.RootNode.DescendantNodesAndTokens().Should().ContainSingle<HttpBodyNode>().Which;
var requestNode = result.SyntaxTree.RootNode.DescendantNodesAndTokens().Should().ContainSingle<HttpUrlNode>().Which;
requestNode
.ChildTokens.Select(t => new { t.Text, t.Kind })
.Should().BeEquivalentSequenceTo(
Expand Down
15 changes: 15 additions & 0 deletions src/Microsoft.DotNet.Interactive.Http.Tests/ParserTests.Url.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,20 @@ public void Invalid_url_produces_a_diagnostic()
lineSpan.EndLinePosition.Line.Should().Be(0);
lineSpan.EndLinePosition.Character.Should().Be(12);
}


[Fact]
public void Punctuation_at_url_start_produces_a_diagnostic()
{
var code = """
GET /https://example.com
""";

var result = Parse(code);

var diagnostic = result.SyntaxTree.RootNode.DescendantNodesAndTokens().Should().ContainSingle<HttpUrlNode>()
.Which.GetDiagnostics().Should().ContainSingle()
.Which;
}
}
}