Closed
Bug 1389099
Opened 4 years ago
Closed 3 years ago
Unicode characters broken when __MSG_... in css file
Categories
(WebExtensions :: Untriaged, defect, P5)
Tracking
(firefox62 verified)
VERIFIED
FIXED
mozilla62
| Tracking | Status | |
|---|---|---|
| firefox62 | --- | verified |
People
(Reporter: yfdyh000, Assigned: robwu)
References
Details
(Keywords: intl)
Attachments
(3 files)
I noticed the problem from https://github.com/Robbendebiene/Gesturefy/pull/18#issuecomment-321553312. STR: 1. Load the testcase.xpi in about:debugging#addons. 2. Click the added toolbar-button, check the popup, the second line is garbled. Actual results: Unicode characters broken, regardless of the css or html encoding. Expected results: Correctly handle characters.
Updated•4 years ago
|
Flags: needinfo?(amckay)
Updated•4 years ago
|
Flags: needinfo?(amckay)
Priority: -- → P5
| Assignee | ||
Comment 1•3 years ago
|
||
While auditing the code, I found it peculiar that the stream converter for CSS converted the input (stream) to a binary string, without any regard for character encoding, localized the string, and then generated a new stream based on it.
I created a test case where I embedded multi-byte UTF-8, like this:
content style:
body::before {
content: 'Here is some poop: Assignee: nobody → rob
| Comment hidden (mozreview-request) |
Comment 3•3 years ago
|
||
| mozreview-review | ||
Comment on attachment 8974162 [details] Bug 1389099 - Properly encode multi-byte translations in CSS https://reviewboard.mozilla.org/r/242436/#review248388 I think there's probably a simpler way to do this, but Kris knows better than I do, redirect to him.
Updated•3 years ago
|
Attachment #8974162 -
Flags: review?(aswan) → review?(kmaglione+bmo)
Comment 4•3 years ago
|
||
| mozreview-review | ||
Comment on attachment 8974162 [details] Bug 1389099 - Properly encode multi-byte translations in CSS https://reviewboard.mozilla.org/r/242436/#review248412 ::: toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js:23 (Diff revision 1) > > AddonTestUtils.init(this); > > createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "42"); > > +const PILE_OF_POO = "\uD83D\uDCA9"; // Pile of Poo (some multi-byte unicode character). No. Nothing of the sort in any code in any code I have to deal with in my daily life. Pick a reasonable multi-byte character. ::: toolkit/components/utils/simpleServices.js:67 (Diff revision 1) > - .createInstance(Ci.nsIStringInputStream); > - > - stream.data = aAddon.localize(aString); > - return stream; > + let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"] > + .createInstance(Ci.nsIScriptableUnicodeConverter); > + converter.charset = "UTF-8"; > + return converter.convertToInputStream(aString); nsIScriptableUnicodeConverter is deprecated. Please use TextEncoder instead.
Attachment #8974162 -
Flags: review?(kmaglione+bmo) → review-
| Comment hidden (mozreview-request) |
| Assignee | ||
Comment 6•3 years ago
|
||
I have replaced the Pile of Poo character with some bytes from an existing web platform test: https://searchfox.org/mozilla-central/rev/5ff2d7683078c96e4b11b8a13674daded935aa44/testing/web-platform/tests/encoding/api-basics.html#28 (ignore me below - I am testing Bugzilla because comment 1 is cut off) Test, expect some text after this:
| Assignee | ||
Comment 7•3 years ago
|
||
Apparently it's known that comments are sometimes truncated on BMO: bug 1253535
Updated•3 years ago
|
Attachment #8974162 -
Flags: review?(aswan)
| Comment hidden (mozreview-request) |
Comment 9•3 years ago
|
||
| mozreview-review | ||
Comment on attachment 8974162 [details] Bug 1389099 - Properly encode multi-byte translations in CSS https://reviewboard.mozilla.org/r/242436/#review250506 Thanks. Sorry for the harsh response in the last review, but in the future, please do not put poop emojis in front of me. I (and many other people) find them disgusting, and shouldn't have to worry about stumbling across them in entirely fecal-unrelated source code. ::: toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js:121 (Diff revision 3) > cssURL = cssURL.replace(/foo.css$/, "locale.css"); > > css = await contentPage.fetch(cssURL); > equal(css, '* { content: "en-US ltr rtl left right" }', "CSS file localized in mochitest scope"); > > + cssURL = cssURL.replace(/locale\.css$/, "multibyte.css"); This is getting gross. Let's just have the extension send the base URL and append the various CSS filenames to it when we need them. ::: toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js:123 (Diff revision 3) > css = await contentPage.fetch(cssURL); > equal(css, '* { content: "en-US ltr rtl left right" }', "CSS file localized in mochitest scope"); > > + cssURL = cssURL.replace(/locale\.css$/, "multibyte.css"); > + css = await contentPage.fetch(cssURL); > + equal(css, `body::before { content: '${MULTIBYTE_STRING}'; } body::after { content: '${MULTIBYTE_STRING}'; }`, "CSS file contains multibyte string"); Can you move this to a helper function something like: getCSS(a, b) { return `a { content: '${a}' } b { content: '${b}' }` } and then do: getCSS(MULTIBYTE_STRING, "__MSG_multibyteKey__"); ... getCSS(MULTIBYTE_STRING, MULTIBYTE_STRING); ? ::: toolkit/components/utils/simpleServices.js:68 (Diff revision 3) > - > - stream.data = aAddon.localize(aString); > + let stream = Cc["@mozilla.org/io/arraybuffer-input-stream;1"] > + .createInstance(Ci.nsIArrayBufferInputStream); > + stream.setData(bytes, 0, bytes.byteLength); Please add a Components.Constructor for this above: const ArrayBufferStream = Components.Constructor("@mozilla.org/io/arraybuffer-input-stream;1", "nsIArrayBufferInputStream", "setData");
Attachment #8974162 -
Flags: review?(kmaglione+bmo) → review+
| Comment hidden (mozreview-request) |
Comment 11•3 years ago
|
||
We're sorry, Autoland could not rebase your commits for you automatically. Please manually rebase your commits and try again. hg error in cmd: hg rebase -s 834eb86cdb11be66bf5e84be0180c8d2fad94b2e -d a00ab75aea2b: rebasing 464023:834eb86cdb11 "Bug 1389099 - Properly encode multi-byte translations in CSS r=kmag" (tip) merging toolkit/components/utils/simpleServices.js warning: conflicts while merging toolkit/components/utils/simpleServices.js! (edit, then use 'hg resolve --mark') unresolved conflicts (see hg resolve, then hg rebase --continue)
| Comment hidden (mozreview-request) |
Comment 13•3 years ago
|
||
Pushed by rob@robwu.nl: https://hg.mozilla.org/integration/autoland/rev/c4caca025498 Properly encode multi-byte translations in CSS r=kmag
Comment 14•3 years ago
|
||
Backed out changeset c4caca025498 (bug 1389099) for failing toolkit/components/extensions/test/xpcshell/test_locale_converter.js Backout link: https://hg.mozilla.org/integration/autoland/rev/672e64a2425343f6098aeaef0b14444ee6133138 Push with failures: https://treeherder.mozilla.org/#/jobs?repo=autoland&revision=c4caca02549844815d894a60acf340cade739cc1 Failure log: https://treeherder.mozilla.org/logviewer.html#?job_id=179025175&repo=autoland&lineNumber=2331
Flags: needinfo?(rob)
Comment 15•3 years ago
|
||
Pushed by rob@robwu.nl: https://hg.mozilla.org/integration/mozilla-inbound/rev/fb806e16195a Properly encode multi-byte translations in CSS r=kmag
| Assignee | ||
Updated•3 years ago
|
Flags: needinfo?(rob)
Comment 16•3 years ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/fb806e16195a
Status: NEW → RESOLVED
Closed: 3 years ago
status-firefox62:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla62
Comment 17•3 years ago
|
||
I can reproduce this issue on Firefox 60.0.1 (20180516032328) under Win 7 64-bit and Mac OS X 10.13.3. The second line is broken, as presented in the step 2 from the description. This issue is verified as fixed on Firefox 62.0a1(20180525005138) under Win 7 64-bit and Mac OS X 10.13.3.
Status: RESOLVED → VERIFIED
Updated•3 years ago
|
status-firefox57:
affected → ---
Updated•3 years ago
|
Product: Toolkit → WebExtensions
You need to log in
before you can comment on or make changes to this bug.
Description
•