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

WindowsPrintConnector Regex not working on PHP 7.3 #670

Closed
Chris-wg opened this issue Dec 8, 2018 · 2 comments
Closed

WindowsPrintConnector Regex not working on PHP 7.3 #670

Chris-wg opened this issue Dec 8, 2018 · 2 comments
Labels
Milestone

Comments

@Chris-wg
Copy link

Chris-wg commented Dec 8, 2018

In WindowsPrintConnector, the regex below breaks on PHP 7.3, which made some changes to how preg_match works.

The error is

WindowsPrintConnector.php Line:126 "preg_match(): Compilation failed: invalid range in character class at offset 29"

The regex is:

const REGEX_SMB = "/^smb:\/\/([\s\d\w-]+(:[\s\d\w-+]+)?@)?([\d\w-]+\.)*[\d\w-]+\/([\d\w-]+\/)?[\d\w-]+(\s[\d\w-]+)*$/";

According to https://www.debuggex.com/, the issue is with the second pattern

(:[\s\d\w-+]+)

I am not an expert with regex, but I find it works if the dash is removed

(:[\s\d\w+]+)

I believe this regex was changed to add the interior plus sign in

#392

@mike42 mike42 added the bug label Dec 10, 2018
@mike42
Copy link
Owner

mike42 commented Dec 19, 2018

I have been able to replicate this on PHP 7.3 (the unit tests catch it), so let's call it a bug. Thanks for reporting.

Unfortunately I think your change would reject lots of valid printer names, so let's keep thinking.

    /**
     * Test for correct identification of bogus or non-supported Samba strings.
     */
    public function testSambaRegex()
    {
        $good = array("smb://foo/bar",
                "smb://foo/bar baz",
                "smb://bob@foo/bar",
                "smb://bob:secret@foo/bar",
                "smb://foo-computer/FooPrinter",
                "smb://foo-computer/workgroup/FooPrinter",
                "smb://foo-computer/Foo-Printer",
                "smb://foo-computer/workgroup/Foo-Printer",
                "smb://foo-computer/Foo Printer",
                "smb://foo-computer.local/Foo Printer",
                "smb://127.0.0.1/abcd"
        );
        $bad = array("",
                "http://google.com",
                "smb:/foo/bar",
                "smb://",
                "smb:///bar",
                "smb://@foo/bar",
                "smb://bob:@foo/bar",
                "smb://:secret@foo/bar",
                "smb://foo/bar/baz/quux",
                "smb://foo-computer//FooPrinter");
        foreach ($good as $item) {
            $this -> assertTrue(preg_match(WindowsPrintConnector::REGEX_SMB, $item) == 1, "Windows samba regex should pass '$item'.");
        }
        foreach ($bad as $item) {
            $this -> assertTrue(preg_match(WindowsPrintConnector::REGEX_SMB, $item) != 1, "Windows samba regex should fail '$item'.");
        }
    }

@mike42 mike42 added this to the 2.1 milestone Jan 30, 2019
@mike42
Copy link
Owner

mike42 commented Feb 17, 2019

This fix has been released in v2.1 today.

@mike42 mike42 closed this as completed Feb 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants