Page MenuHomePhabricator

Provide "phutil_build_http_querystring()", like "http_build_query()" but not wrong by default
ClosedPublic

Authored by epriestley on Jan 28 2019, 11:10 PM.
Tags
None
Referenced Files
F18635055: D20049.diff
Wed, Sep 17, 12:35 AM
F18619070: D20049.id47901.diff
Mon, Sep 15, 1:41 AM
F18595307: D20049.id47887.diff
Fri, Sep 12, 9:12 PM
F18566939: D20049.id.diff
Tue, Sep 9, 3:01 PM
F18443802: D20049.id.diff
Sun, Aug 31, 7:14 PM
F18417912: D20049.diff
Sat, Aug 30, 12:25 PM
F18107996: D20049.id47887.diff
Aug 11 2025, 4:14 AM
F18107721: D20049.id47884.diff
Aug 11 2025, 2:37 AM
Subscribers
None

Details

Summary

See D20039. Although http_build_query() works fine for the most part, it does the wrong thing by default if arg_separator.output is set in configuration.

Provide a wrapper which forces the expected behavior.

Test Plan

Ran unit tests.

Diff Detail

Repository
rPHU libphutil
Branch
http1
Lint
Lint Errors
SeverityLocationCodeMessage
Errorsrc/utils/utils.php:1317XHP45PHP Compatibility
Errorsrc/utils/utils.php:1317XHP45PHP Compatibility
Unit
Tests Passed
Build Status
Buildable 21744
Build 29671: Run Core Tests
Build 29670: arc lint + arc unit

Event Timeline

src/markup/engine/remarkup/blockrule/PhutilRemarkupTestInterpreterRule.php
14

HA HA HA THIS TEST WOULD PREVIOUSLY FAIL UNDER UNUSUAL VALUES OF arg_separator.output HA HA HA PHP

Marking this as changes requested because I think the PhutilURI.php change is wrong.

src/markup/engine/remarkup/blockrule/PhutilRemarkupTestInterpreterRule.php
14

yourewelcome

src/parser/PhutilURI.php
177

Dangling arguments?

This revision now requires changes to proceed.Jan 29 2019, 3:25 AM
src/parser/PhutilURI.php
177

Ah, thanks!

  • Remove dangling arguments.
This revision is now accepted and ready to land.Jan 29 2019, 3:33 AM
  • Switch to PHP_QUERY_RFC3986 mode.
  • Add unit tests.

This corresponds to rawurlencode(). The default mode (PHP_QUERY_RFC1738) corresponds to urlencode().

The only differences for this new mode are:

  • Space is encoded as %20 (instead of +).
  • "~" is not encoded (instead of %7F).

The space encoding as %20 seems strongly preferable, since any reasonable parser can and should handle it unambiguously, while the meaning of + to parsers is ambiguous.

This is also what Duo (at least) expects, and what we'd expect ourselves.

  • Use rawurlencode(), not http_build_query(), because PHP_QUERY_RFC3986 requires PHP 5.4 or newer.

This could probably use another quick look, see also D20053.

I added a note for the version thing in T7408.

This revision is now accepted and ready to land.Jan 30 2019, 6:20 AM
This revision was automatically updated to reflect the committed changes.