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

Review usages of String_ to correctly handle escaping #8161

Open
AndrolGenhald opened this issue Jun 24, 2022 · 2 comments
Open

Review usages of String_ to correctly handle escaping #8161

AndrolGenhald opened this issue Jun 24, 2022 · 2 comments
Labels

Comments

@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Jun 24, 2022

String_::$value unescapes the string, String_::$attributes["rawValue"] was recently added for this. We should upgrade the parser version and fix these issues.

@psalm-github-bot
Copy link

psalm-github-bot bot commented Jun 24, 2022

I found these snippets:

https://psalm.dev/r/c53ed4f377
<?php

/**
 * @return "\t"
 */
function foobar(): string
{
    return "\t";
}
Psalm output (using commit f2f211c):

ERROR: InvalidReturnStatement - 8:12 - The inferred type ''\t'' does not match the declared return type ''\\t'' for foobar

ERROR: InvalidReturnType - 4:12 - The declared return type ''\\t'' for foobar is incorrect, got ''\t''
https://psalm.dev/r/7c454c91bd
<?php

/**
 * @return "	"
 */
function foobar(): string
{
    return "\t";
}
Psalm output (using commit f2f211c):

ERROR: InvalidReturnStatement - 8:12 - The inferred type ''\t'' does not match the declared return type '' '' for foobar

ERROR: InvalidReturnType - 4:12 - The declared return type '' '' for foobar is incorrect, got ''\t''
https://psalm.dev/r/cc297a99cb
<?php

/** @var array<string, true> */
$arr = ["\t" => true];
if (isset($arr["\t"])) {
    $shouldBePossiblyUndefinedArrayStringOffset = $arr["	"];
    /** @psalm-trace $shouldBePossiblyUndefinedArrayStringOffset */;
}
Psalm output (using commit f2f211c):

INFO: Trace - 7:68 - $shouldBePossiblyUndefinedArrayStringOffset: true
https://psalm.dev/r/30427475aa
<?php

$arr = ["\\test" => true];
$unset = $arr['\\test'];
$unset2 = $arr["\\\\test"];
Psalm output (using commit f2f211c):

ERROR: InvalidArrayOffset - 5:11 - Cannot access value on variable $arr using offset value of '\\test', expecting '\test'

INFO: MixedAssignment - 5:1 - Unable to determine the type that $unset2 is being assigned to

@AndrolGenhald
Copy link
Collaborator Author

Ok, part of this was because I was dumb and was using "\\" in Psalm's tests when it actually needs to be "\\\\" to represent "\\" because the whole thing is in single quotes. I think there are related issues though so I'll leave this open.

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

1 participant