phpdoc-parser icon indicating copy to clipboard operation
phpdoc-parser copied to clipboard

Unescape constant strings

Open rvanvelzen opened this issue 1 year ago • 3 comments

Fix #142

rvanvelzen avatar Aug 09 '22 06:08 rvanvelzen

I would expect double quoted string to support the same escaping sequences as PHP. See https://github.com/nikic/PHP-Parser/blob/master/lib/PhpParser/Node/Scalar/String_.php#L71-L130

JanTvrdik avatar Aug 09 '22 08:08 JanTvrdik

I initially was going to do so, but didn't for parity with Psalm. I'd be more than happy to mirror PHP's functionality though, if @ondrejmirtes also agrees :)

rvanvelzen avatar Aug 09 '22 08:08 rvanvelzen

Yes, parity with PHP would be great, we're in a very edge case territory anyway. And inform the Psalm maintainers afterwards 😊 BTW is this a BC break? Do we need a feature flag for the new behaviour?

ondrejmirtes avatar Aug 09 '22 08:08 ondrejmirtes

I've basically copied most of the implementation from PHP-Parser, but that probably needs to be mentioned somewhere. Any suggestions?

rvanvelzen avatar Oct 17 '22 15:10 rvanvelzen

A github.com permalink in a code comment would be fine I think.

ondrejmirtes avatar Oct 17 '22 15:10 ondrejmirtes

This is gonna need some modification and a bleedingEdge toggle in phpstan-src too, right?

ondrejmirtes avatar Oct 17 '22 15:10 ondrejmirtes

It should only require a feature toggle :)

rvanvelzen avatar Oct 17 '22 15:10 rvanvelzen

What about the bool $trimStrings = false? parameter? Shouldn't we eventually get rid of it? In PHPStan it's probably called with false...

ondrejmirtes avatar Oct 17 '22 15:10 ondrejmirtes

What about the bool $trimStrings = false? parameter? Shouldn't we eventually get rid of it? In PHPStan it's probably called with false...

I would definitely like to get rid of it, especially because it is used with both true/false internally. @method parameter default values are parsed without unescaping, which eventually leads to unescaped values in PHPStan as well. Those never really propagate anywhere though…

There isn't a pure BC-friendly approach to removing it I'm afraid, but I really don't think it should be used at all so maybe it's not that bad?

rvanvelzen avatar Oct 20 '22 06:10 rvanvelzen

Thank you!

ondrejmirtes avatar Oct 20 '22 07:10 ondrejmirtes