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

cro::uri generating internal Nil warning #197

Open
coke opened this issue Jul 18, 2024 · 2 comments · May be fixed by croservices/cro-core#40
Open

cro::uri generating internal Nil warning #197

coke opened this issue Jul 18, 2024 · 2 comments · May be fixed by croservices/cro-core#40

Comments

@coke
Copy link

coke commented Jul 18, 2024

raku -MCro::HTTP::Client -e 'my $a = Cro::HTTP::Client.new; my $b = await $a.get: "https://www.reddit.com/r/perl6/comments/42dkme/perl6_not_being_an_interpreted_language/"'
Use of Nil in string context

Something about this particular URL (which returns a 302 if it matters) triggers it.

@coke coke changed the title HTTP::Client generating internal Nil warning cro::uri generating internal Nil warning Jul 18, 2024
@patrickbkr
Copy link
Member

As you already diagnosed, it's in this line.

method path-absolute($/) {
    my $result = '/';
    $result ~= $_<pchars>.ast with $<segment-nz>;
    $result ~= '/' ~ $_<pchars>.ast for @$<segment>; # <-- here
    make $result; 
}

That's an action method for a grammar.

A quick debug output gives:

Match.new(:orig("/r/perl6/comments/42dkme/perl6_not_being_an_interpreted_language/?rdt=61905"), :from(3), :pos(8), :hash(Map.new((:pchars(Match.new(:orig("/r/perl6/comments/42dkme/perl6_not_being_an_interpreted_language/?rdt=61905"), :from(3), :pos(8), :list(([Match.new(:orig("/r/perl6/comments/42dkme/perl6_not_being_an_interpreted_language/?rdt=61905"), :from(3), :pos(8))],)), :made("perl6")))))), :made("perl6"))
Match.new(:orig("/r/perl6/comments/42dkme/perl6_not_being_an_interpreted_language/?rdt=61905"), :from(9), :pos(17), :hash(Map.new((:pchars(Match.new(:orig("/r/perl6/comments/42dkme/perl6_not_being_an_interpreted_language/?rdt=61905"), :from(9), :pos(17), :list(([Match.new(:orig("/r/perl6/comments/42dkme/perl6_not_being_an_interpreted_language/?rdt=61905"), :from(9), :pos(17))],)), :made("comments")))))), :made("comments"))
Match.new(:orig("/r/perl6/comments/42dkme/perl6_not_being_an_interpreted_language/?rdt=61905"), :from(18), :pos(24), :hash(Map.new((:pchars(Match.new(:orig("/r/perl6/comments/42dkme/perl6_not_being_an_interpreted_language/?rdt=61905"), :from(18), :pos(24), :list(([Match.new(:orig("/r/perl6/comments/42dkme/perl6_not_being_an_interpreted_language/?rdt=61905"), :from(18), :pos(24))],)), :made("42dkme")))))), :made("42dkme"))
Match.new(:orig("/r/perl6/comments/42dkme/perl6_not_being_an_interpreted_language/?rdt=61905"), :from(25), :pos(64), :hash(Map.new((:pchars(Match.new(:orig("/r/perl6/comments/42dkme/perl6_not_being_an_interpreted_language/?rdt=61905"), :from(25), :pos(64), :list(([Match.new(:orig("/r/perl6/comments/42dkme/perl6_not_being_an_interpreted_language/?rdt=61905"), :from(25), :pos(64))],)), :made("perl6_not_being_an_interpreted_language")))))), :made("perl6_not_being_an_interpreted_language"))
Match.new(:orig("/r/perl6/comments/42dkme/perl6_not_being_an_interpreted_language/?rdt=61905"), :from(65), :pos(65))

Notice that the last match is empty. That's the emptyness after the last "/" and before the "?" in the URI.

In similar action methods a few lines down I see guards for this. Replicating them gives:

$result ~= '/' ~ ($_<pchars> ?? $_<pchars>.ast !! ~$_) for @$<segment>;

This fixes the issue.

But I have no idea what's happening. Can I summon a regex expert? Maybe @lizmat?

  • What is .ast meant to return?
  • Why is the fallback ~$_ instead of just ''?

@patrickbkr
Copy link
Member

I think I understand a bit. ~$_ is the unprocessed input. @$ is a list of matched input. If the element in that list happens to be a pchars, then take the processed output (pchars percent-encodes it's content), if not, just take the input unprocessed.

patrickbkr added a commit to patrickbkr/cro-core that referenced this issue Jul 19, 2024
patrickbkr added a commit to patrickbkr/cro-core that referenced this issue Jul 19, 2024
patrickbkr added a commit to patrickbkr/cro-core that referenced this issue Jul 19, 2024
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 a pull request may close this issue.

2 participants