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

Running URI through UriNormalize Filter appends / - causes Hostname TLD check to always fail #3

Closed
weierophinney opened this issue Dec 31, 2019 · 2 comments

Comments

@weierophinney
Copy link
Member

If you run any hostname through UriNormalize, at some point the normalize function in the Uri module is run. This module calls normalizePath function.

This function appends a / to the end of the URI.

Next, when you try to validate the URI with Hostname validator with 'useTldCheck' => true, in the options, it will always fail.

hostname


Steps to reproduce

Have the following in a fieldset

        $this->add(
            [
                'name'       => 'someUrl',
                'required'   => true,
                'type'       => Text::class,
                'options'    => [
                    'label' => 'Some URL',
                ],
                'attributes' => [
                    'maxlength' => 100,
                ],
            ]
        );

Have the following in an InputFilter:

        $this->add(
            [
                'name'       => 'someUrl',
                'required'   => true,
                'filters'    => [
                    ['name' => StringTrim::class],
                    ['name' => StripTags::class],
                    [
                        'name'    => ToNull::class,
                        'options' => [
                            'type' => ToNull::TYPE_STRING,
                        ],
                    ],
                    [
                        'name'    => UriNormalize::class,
                        'options' => [
                            'enforcedScheme' => 'https',
                        ],
                    ],
                ],
                'validators' => [
                    [
                        'name'    => StringLength::class,
                        'options' => [
                            'min' => 1,
                            'max' => 100,
                        ],
                    ],
                    [
                        'name'    => Hostname::class,
                        'options' => [
                            'allow'       => Hostname::ALLOW_DNS,
                            // Allow only DNS names
                            'useIdnCheck' => true,
                            // Check IDN domains - International Domain Names - supports international characters in DNS of country TLD, e.g. *.de (Germany) TLD
                            'useTldCheck' => true,
                            // Validates the existence of the TLD itself (the .com part of the domain)
                        ],
                    ],
                    [
                        'name'    => Uri::class,
                        'options' => [
                            'allowRelative' => false,
                        ],
                    ],
                ],
            ]
        );

I've got a few more issues reported that I'm solving, next to projects and a full-time job, I most likely will not have time to fix this. Would appreciate someone stepping in to fix this one. If not I might get around to it after other issues in zend-form and/or zend-inputfilter are finished.


Originally posted by @rkeet at zendframework/zend-validator#235

@weierophinney
Copy link
Member Author

                    // Remove trailing '/' char from tld string if present
                    if (substr($this->tld, -1) === '/') {
                        $this->tld = substr($this->tld, 0, -1);
                    }

I would suggest this after line 2052 in Hostname.php file.


Originally posted by @rkeet at zendframework/zend-validator#235 (comment)

@samsonasik
Copy link
Member

If I understand correctly, the UriNormalize you setup already will generate full URI, eg: 'https://www.google.com' which it is already not a valid hostname with or without / suffix, you probably just need Uri validator only instead.

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

2 participants