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

filter_input types too generic #9760

Closed
kkmuffme opened this issue May 8, 2023 · 2 comments · Fixed by #10498
Closed

filter_input types too generic #9760

kkmuffme opened this issue May 8, 2023 · 2 comments · Fixed by #10498
Labels
easy problems Issues that can be fixed without background knowledge of Psalm enhancement good first issue Help wanted internal stubs/callmap

Comments

@kkmuffme
Copy link
Contributor

kkmuffme commented May 8, 2023

https://psalm.dev/r/10b253ba58

filter_input types are extremely generic and should be updated so they work like the superglobals ($_SERVER,...) already do.
e.g. it should be false|null|string here

In this case https://psalm.dev/r/5b0fa23243 it should just be string

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/10b253ba58
<?php

$tmp1 = filter_input( INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL );
/** @psalm-trace $tmp1 */;

$tmp2 = $_SERVER['QUERY_STRING'];
/** @psalm-trace $tmp2 */;
Psalm output (using commit d4c5f85):

INFO: MixedAssignment - 3:1 - Unable to determine the type that $tmp1 is being assigned to

INFO: Trace - 4:26 - $tmp1: false|mixed

ERROR: PossiblyUndefinedArrayOffset - 6:9 - Possibly undefined array key $_SERVER['QUERY_STRING'] on array{APP_DEBUG?: bool|string, APP_ENV?: string, AUTH_TYPE?: non-empty-string, CONTENT_LENGTH?: string, CONTENT_TYPE?: string, DOCUMENT_ROOT?: non-empty-string, FCGI_ROLE?: non-empty-string, GATEWAY_INTERFACE?: non-empty-string, HOME?: non-empty-string, HTTPS?: string, HTTP_ACCEPT?: non-empty-string, HTTP_ACCEPT_CHARSET?: non-empty-string, HTTP_ACCEPT_ENCODING?: non-empty-string, HTTP_ACCEPT_LANGUAGE?: non-empty-string, HTTP_CACHE_CONTROL?: non-empty-string, HTTP_CDN_LOOP?: non-empty-string, HTTP_CF_CONNECTING_IP?: non-empty-string, HTTP_CF_IPCOUNTRY?: non-empty-string, HTTP_CF_VISITOR?: non-empty-string, HTTP_CLIENT_IP?: non-empty-string, HTTP_CONNECTION?: non-empty-string, HTTP_COOKIE?: non-empty-string, HTTP_DNT?: non-empty-string, HTTP_HOST?: non-empty-string, HTTP_PRIORITY?: non-empty-string, HTTP_REFERER?: non-empty-string, HTTP_SEC_CH_UA?: non-empty-string, HTTP_SEC_CH_UA_MOBILE?: non-empty-string, HTTP_SEC_CH_UA_PLATFORM?: non-empty-string, HTTP_SEC_FETCH_DEST?: non-empty-string, HTTP_SEC_FETCH_MODE?: non-empty-string, HTTP_SEC_FETCH_SITE?: non-empty-string, HTTP_SEC_FETCH_USER?: non-empty-string, HTTP_UPGRADE_INSECURE_REQUESTS?: non-empty-string, HTTP_USER_AGENT?: non-empty-string, HTTP_X_FORWARDED_FOR?: non-empty-string, HTTP_X_FORWARDED_PROTO?: non-empty-string, HTTP_X_REAL_IP?: non-empty-string, ORIG_PATH_INFO?: non-empty-string, PATH?: non-empty-string, PATH_INFO?: non-empty-string, PATH_TRANSLATED?: non-empty-string, PHP_AUTH_DIGEST?: non-empty-string, PHP_AUTH_PW?: non-empty-string, PHP_AUTH_USER?: non-empty-string, PHP_SELF?: non-empty-string, QUERY_STRING?: string, REDIRECT_REMOTE_USER?: non-empty-string, REDIRECT_STATUS?: non-empty-string, REMOTE_ADDR?: non-empty-string, REMOTE_HOST?: non-empty-string, REMOTE_PORT?: string, REMOTE_USER?: non-empty-string, REQUEST_METHOD?: non-empty-string, REQUEST_SCHEME?: non-empty-string, REQUEST_TIME?: int<1683587010, max>, REQUEST_TIME_FLOAT?: float, REQUEST_URI?: non-empty-string, SCRIPT_FILENAME?: non-empty-string, SCRIPT_NAME?: non-empty-string, SERVER_ADDR?: non-empty-string, SERVER_ADMIN?: non-empty-string, SERVER_NAME?: non-empty-string, SERVER_PORT?: non-empty-string, SERVER_PROTOCOL?: non-empty-string, SERVER_SIGNATURE?: non-empty-string, SERVER_SOFTWARE?: non-empty-string, USER?: non-empty-string, argc?: int<1, max>, argv?: non-empty-list<string>, ...<non-empty-string, string>}

INFO: Trace - 7:26 - $tmp2: string

INFO: UnusedVariable - 3:1 - $tmp1 is never referenced or the value is not used

INFO: UnusedVariable - 6:1 - $tmp2 is never referenced or the value is not used
https://psalm.dev/r/5b0fa23243
<?php

if ( isset( $_SERVER['QUERY_STRING'] ) ) {
    $tmp1 = filter_input( INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL );
    /** @psalm-trace $tmp1 */;
    
    $tmp2 = $_SERVER['QUERY_STRING'];
	/** @psalm-trace $tmp2 */;
}
Psalm output (using commit d4c5f85):

INFO: MixedAssignment - 4:5 - Unable to determine the type that $tmp1 is being assigned to

INFO: Trace - 5:30 - $tmp1: false|mixed

INFO: Trace - 8:27 - $tmp2: string

INFO: UnusedVariable - 4:5 - $tmp1 is never referenced or the value is not used

INFO: UnusedVariable - 7:5 - $tmp2 is never referenced or the value is not used

@orklah
Copy link
Collaborator

orklah commented May 9, 2023

that would make sense :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy problems Issues that can be fixed without background knowledge of Psalm enhancement good first issue Help wanted internal stubs/callmap
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants