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

InnerBrowser Unknown modifier #3581

Closed
nathanphan opened this issue Oct 5, 2016 · 4 comments
Closed

InnerBrowser Unknown modifier #3581

nathanphan opened this issue Oct 5, 2016 · 4 comments

Comments

@nathanphan
Copy link

@nathanphan nathanphan commented Oct 5, 2016

What are you trying to achieve?

I am using click like this:

$I->click('Create Hotfix', 'li.active');

I see this in log

preg_match(): Unknown modifier '/' in file /var/www/devops/protected/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php at line 202

My functional.suite.yml is

modules: enabled: # add framework module here - Yii1: appPath: 'public/test.php' url: 'http://mysite.local/test.php'

When I use var_dump before line 202 in InnerBrowser.php for the $pattern variable, it gives me this

/^http\\://mysite\\.local$/u

Which is wrong. It should be

/^http:\/\/mysite\.local$/u

Please help

@amashigeseiji
Copy link
Contributor

@amashigeseiji amashigeseiji commented Oct 6, 2016

I think the cause of this problem is \Codeception\Module\Yii1::getDomainRegex:227.

InnerBrowser::isInternalDomain calls \Codeception\Module\Yii1::getInternalDomains.

line 248 of \Codeception\Module\Yii1(getInternalDomain) is:

        $domains = [$this->getDomainRegex(Yii::app()->request->getHostInfo())];

and line 227 of \Codeception\Module\Yii1(getDomainRegex) is:

        if (preg_match('#https?://(.*?)/#', $template, $matches)) {

Yii::app()->request->getHostInfo() returns http://mysite.local, not http://mysite.local/,
so preg_match on line 227 (\Codeception\Module\Yii1::getDomainRegex) does not operate as expected.
Regex pattern of preg_match on line 227 expects argument with trailing slash like http://mysite.local/.

I think this commit will solve your problem.

@nathanphan
Copy link
Author

@nathanphan nathanphan commented Oct 6, 2016

I got your point but when it comes to line 202 in InnerBrowser.php

the $pattern and $domain cannot be matched.

@amashigeseiji
Copy link
Contributor

@amashigeseiji amashigeseiji commented Oct 6, 2016

yes, I see.
This is a bug of Yii1::getInternalDomain that returns invalid regex pattern.
getInternalDomain should return /^mysite.local$/u, not /^https?://mysite.local$/u or /^https?:\/\/mysite.local$/u.

argument of InnerBrowser::isInternalDomain is:

169            if (preg_match('#^(//|https?://(?!localhost))#', $uri)) {
170                $hostname = parse_url($uri, PHP_URL_HOST);
171                if (!$this->isInternalDomain($hostname)) {

$hostname is like mysite.local, so that /^https?:\/\/mysite.local$/u does not match mysite.local and InnerBrowser::isInternalDomain returns false. It is not expected.

@nathanphan
Copy link
Author

@nathanphan nathanphan commented Oct 6, 2016

I have pull request here #3582

but my editor is some kind of suck...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants