Skip to content

Fix issue while loading a container #41

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

Merged
merged 1 commit into from
Mar 11, 2019
Merged

Conversation

jdeniau
Copy link
Contributor

@jdeniau jdeniau commented Mar 5, 2019

When the URI of the container contains escaped characters like %2F, simplexml_load_file throw an error.

According to the documentation :

Libxml 2 unescapes the URI, so if you want to pass e.g. b&c as the URI parameter a, you have to call simplexml_load_file(rawurlencode('http://example.com/?a=' . urlencode('b&c'))). Since PHP 5.1.0 you don't need to do this because PHP will do it for you.

I don't understand exactly what should not be done since PHP 5.1.0, but with PHP 7.2, I reproduced the following error :

$jd = 'jdjd/test.xml';
$jdSlash = rawurlencode('jdjd/test.xml');
$jnSlash = rawurlencode('jn%2Fjn/test.xml');
$jn = 'jn%2Fjn/test.xml';

var_dump($jd); // string(13) "jdjd/test.xml"
var_dump(simplexml_load_file($jd)); // OK object(SimpleXMLElement) 

var_dump($jdSlash); // string(15) "jdjd%2Ftest.xml"
var_dump(simplexml_load_file($jdSlash)); // OK object(SimpleXMLElement) 

var_dump($jnSlash); // string(20) "jn%252Fjn%2Ftest.xml"
var_dump(simplexml_load_file($jnSlash)); // OK object(SimpleXMLElement)

var_dump($jn); // string(16) "jn%2Fjn/test.xml"
var_dump(simplexml_load_file($jn)); // PHP Warning:  simplexml_load_file(): I/O warning : failed to load external entity "jn%2Fjn/test.xml"

Another possible fix is to use:

$xml = @simplexml_load_string(file_get_contents($this->containerXml));

@lookyman
Copy link
Collaborator

lookyman commented Mar 5, 2019

I like the simplexml_load_string solution better. Also, could you add a test for that? Thanks!

When the URI of the container contains escaped characters like `%2F`, `simplexml_load_file` throw an error.
@jdeniau
Copy link
Contributor Author

jdeniau commented Mar 5, 2019

@lookyman done

@lookyman lookyman merged commit 649c258 into phpstan:master Mar 11, 2019
@lookyman
Copy link
Collaborator

Thank you!

@jdeniau jdeniau deleted the patch-1 branch March 11, 2019 15:04
@jdeniau jdeniau restored the patch-1 branch March 11, 2019 15:04
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 this pull request may close these issues.

2 participants