Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Unescape constant strings #143

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
ondrejmirtes merged 3 commits into phpstan:1.9.x from rvanvelzen:string-escape
Oct 20, 2022
Merged

Conversation

Copy link
Contributor

@rvanvelzen rvanvelzen commented Aug 9, 2022

Fix #142

mvorisek reacted with heart emoji
Copy link
Collaborator

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

Copy link
Contributor Author

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 :)

Copy link
Member

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?

mvorisek reacted with thumbs up emoji

@@ -137,4 +130,17 @@ private function parseArrayItem(TokenIterator $tokens): Ast\ConstExpr\ConstExprA
return new Ast\ConstExpr\ConstExprArrayItemNode($key, $value);
}

private function trimString(string $string): string
Copy link
Collaborator

@JanTvrdik JanTvrdik Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decode or parse string would be better name

@rvanvelzen rvanvelzen changed the base branch from 1.8.x to 1.9.x October 17, 2022 15:04
Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Member

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

Copy link
Contributor Author

It should only require a feature toggle :)

Copy link
Member

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

);
}

private static function codePointToUtf8(int $num): string
Copy link
Collaborator

@JanTvrdik JanTvrdik Oct 17, 2022
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use mb_chr() or IntlChar::chr() instead?

Copy link
Contributor Author

@rvanvelzen rvanvelzen Oct 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither mbstring nor intl are declared as a dependency, so that would need to be conditional. That would only make the code more complicated for little gain.

Copy link
Contributor Author

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?

Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@JanTvrdik JanTvrdik JanTvrdik left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Cannot use backslash as a literal string in conditional return type

AltStyle によって変換されたページ (->オリジナル) /