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

URI->new('foo', 'http') doesn't set the scheme #88

Open
Corion opened this issue Jul 11, 2021 · 2 comments
Open

URI->new('foo', 'http') doesn't set the scheme #88

Corion opened this issue Jul 11, 2021 · 2 comments

Comments

@Corion
Copy link

Corion commented Jul 11, 2021

The two-argument constructor setting the scheme part of an URL doesn't work (anymore?) as shown in the synopsis, see the attached test.

Due to the deep inheritance tree, I didn't find out where the scheme information gets lost, but either the synopsis should be amended or specifying the scheme in the constructor should be made to work again.

Thanks!

#!perl
use strict;
use warnings;
use Test::More tests => 2;
use URI;

my $uri = URI->new('example', 'example-scheme');
is $uri->scheme, 'example-scheme';

# Also test the synopsis:
my $u2 = URI->new("foo", "http");
is $u2->scheme, 'http';

uri-scheme.t.txt

@oalders
Copy link
Member

oalders commented Jul 12, 2021

I can't actually find a tag from the last 10 years where this works. It looks like it's creating the right class based on the supplied scheme, but sub _scheme is not dealing with this.

#!perl
use strict;
use warnings;
use Test::More tests => 4;
use URI;

my $uri = URI->new('example', 'example-scheme');
is $uri->scheme, 'example-scheme';
is ref $uri, 'URI::_foreign', 'is URI::_foreign';

# Also test the synopsis:
my $u2 = URI->new("foo", "http");
is $u2->scheme, 'http';
is ref $u2, 'URI::http', 'is URI::http';

In URI::_scheme() there is:

    unless (@_) {
	return undef unless $$self =~ /^($scheme_re):/o;
	return $1;
    }

$$self stringifies to example in the first case and foo in the second case, so the match on a scheme will never be successful.

Not quite sure what the correct fix is, but that's just from a quick look.

@choroba
Copy link

choroba commented Feb 4, 2022

It seems to be because of

    $str = "$scheme:$str" unless $str =~ /^$scheme_re:/o ||
                                 $class->_no_scheme_ok;

in URI::_init(). Removing the "no_scheme_ok" check breaks lots of other tests, though.

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

No branches or pull requests

3 participants