Closed Bug 1994996 Opened 8 months ago Closed 3 months ago

Handle unicode headers for tentative setExtraHeaders test

Categories

(Remote Protocol :: WebDriver BiDi, defect, P2)

defect
Points:
2

Tracking

(firefox150 fixed)

RESOLVED FIXED
150 Branch
Tracking Status
firefox150 --- fixed

People

(Reporter: jdescottes, Assigned: jdescottes)

References

Details

(Whiteboard: [webdriver:m19], [wptsync upstream][webdriver:relnote])

Attachments

(3 files)

At the moment we only fail two test cases from the setExtraHeaders test suite, when setting a unicode header '你好世界'

Summary: Handle unicode handers for tentative setExtraHeaders test → Handle unicode headers for tentative setExtraHeaders test
Severity: -- → S3
Points: --- → 2
Priority: -- → P2
Whiteboard: [webdriver:m19]
Assignee: nobody → jdescottes
Status: NEW → ASSIGNED

Hi Kershaw,

In BiDi we are using nsIHttpChannel.setRequestHeader to modify request headers, and there is a webplatform test which asserts that we can set a header with the value 你好世界. But that doesn't seem to work with setRequestHeader (see attached test), the value stored is ``}\u0016L`.

At this point I'm not sure if this a bug in setRequestHeader, or if I should encode the header value before calling setRequestHeader, or if this value is simply not acceptable for a header? Let me know what you think!

Flags: needinfo?(kershaw)

(unassigning for now)

Status: ASSIGNED → NEW

(In reply to Julian Descottes [:jdescottes] from comment #2)

Hi Kershaw,

In BiDi we are using nsIHttpChannel.setRequestHeader to modify request headers, and there is a webplatform test which asserts that we can set a header with the value 你好世界. But that doesn't seem to work with setRequestHeader (see attached test), the value stored is ``}\u0016L`.

At this point I'm not sure if this a bug in setRequestHeader, or if I should encode the header value before calling setRequestHeader, or if this value is simply not acceptable for a header? Let me know what you think!

The issue is in how XPConnect converts a JavaScript string to ACString (the IDL type of setRequestHeader's value parameter). ACString is a raw byte string with no encoding. When XPConnect converts a JS string to ACString, it calls JS_EncodeStringToBuffer which truncates each UTF-16 code unit to its low byte (buffer[i] = char(src[i])). So "你好世界" (U+4F60, U+597D, U+4E16, U+754C) becomes the 4 garbage bytes `}\x16L — just the low byte of each code point.

On the HTTP spec side, RFC 9110 §5.5 allows bytes in the range %x80-FF in header values, and only forbids CR/LF/NUL.
I assume what the WPT expects is the UTF-8 encoding of "你好世界" as raw bytes?
If so, I think the fix can be adding another API to use AUTF8String instead of ACString for the value parameter.

Flags: needinfo?(kershaw)
Attachment #9547704 - Attachment description: Bug 1994996 - WIP modify test to illustrate issue with setRequestHeaders and chinese characters → Bug 1994996 - [necko] Change header value parameters from ACString to AUTF8String for proper UTF-8 support
Status: NEW → ASSIGNED
Pushed by jdescottes@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/c8fcc7daeb65 https://hg.mozilla.org/integration/autoland/rev/2afe0d717f4d [necko] Change header value parameters from ACString to AUTF8String for proper UTF-8 support r=necko-reviewers,Sasha,kershaw
Status: ASSIGNED → RESOLVED
Closed: 4 months ago
Resolution: --- → FIXED
Target Milestone: --- → 150 Branch

Reopening the bug since Bug 2020207 will revert the fix. We need to find a solution for this which doesn't regress other consumers setting reading headers.

Status: RESOLVED → REOPENED
Resolution: FIXED → ---
See Also: → 1835216
Attachment #9549121 - Attachment description: Bug 1994996 - [wdspec] Add test for non-ascii headers with continueRequest → Bug 1994996 - [wdspec] Add tests for non-utf8 headers with various network commands
Pushed by jdescottes@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/c6d98f856c2f https://hg.mozilla.org/integration/autoland/rev/20457722a6da [bidi] Encode/Decode protocol bytes as UTF8 in the network module r=Sasha,valentin
Status: REOPENED → RESOLVED
Closed: 4 months ago3 months ago
Resolution: --- → FIXED
Whiteboard: [webdriver:m19] → [webdriver:m19], [wptsync upstream error]
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/58310 for changes under testing/web-platform/tests
Whiteboard: [webdriver:m19], [wptsync upstream error] → [webdriver:m19], [wptsync upstream]
Upstream PR merged by moz-wptsync-bot
Whiteboard: [webdriver:m19], [wptsync upstream] → [webdriver:m19], [wptsync upstream][webdriver-relnote]
Whiteboard: [webdriver:m19], [wptsync upstream][webdriver-relnote] → [webdriver:m19], [wptsync upstream][webdriver:relnote]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: