Commit 38e75d70 authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃
Browse files

Bug 1666613 - Do not rely on intl.css for text direction in parsererror....

Bug 1666613 - Do not rely on intl.css for text direction in parsererror. r=dom-core,hsivonen,firefox-style-system-reviewers,emilio

Differential Revision: https://phabricator.services.mozilla.com/D244629
parent ac8a9d87
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@
#include "mozilla/dom/ScriptLoader.h"
#include "mozilla/dom/txMozillaXSLTProcessor.h"
#include "mozilla/dom/nsCSPUtils.h"
#include "mozilla/intl/LocaleService.h"
#include "mozilla/CycleCollectedJSContext.h"
#include "mozilla/LoadInfo.h"
#include "mozilla/UseCounter.h"
@@ -1372,12 +1373,6 @@ nsXMLContentSink::ReportError(const char16_t* aErrorText,
  }

  // prepare to set <parsererror> as the document root
  rv = HandleProcessingInstruction(
      u"xml-stylesheet",
      u"href=\"chrome://global/locale/intl.css\" type=\"text/css\"");
  NS_ENSURE_SUCCESS(rv, rv);

  const char16_t* noAtts[] = {0, 0};

  constexpr auto errorNs =
      u"http://www.mozilla.org/newlayout/xml/parsererror.xml"_ns;
@@ -1386,7 +1381,12 @@ nsXMLContentSink::ReportError(const char16_t* aErrorText,
  parsererror.Append((char16_t)0xFFFF);
  parsererror.AppendLiteral("parsererror");

  rv = HandleStartElement(parsererror.get(), noAtts, 0, (uint32_t)-1, 0);
  const char16_t* dirAttr[] = {u"dir", u"ltr", 0, 0};
  if (intl::LocaleService::GetInstance()->IsAppLocaleRTL() &&
      !mDocument->ShouldResistFingerprinting(RFPTarget::JSLocale)) {
    dirAttr[1] = u"rtl";
  }
  rv = HandleStartElement(parsererror.get(), dirAttr, 0, 2, 0);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = HandleCharacterData(aErrorText, NS_strlen(aErrorText), false);
@@ -1396,6 +1396,7 @@ nsXMLContentSink::ReportError(const char16_t* aErrorText,
  sourcetext.Append((char16_t)0xFFFF);
  sourcetext.AppendLiteral("sourcetext");

  const char16_t* noAtts[] = {0, 0};
  rv = HandleStartElement(sourcetext.get(), noAtts, 0, (uint32_t)-1, 0);
  NS_ENSURE_SUCCESS(rv, rv);

+1 −0
Original line number Diff line number Diff line
<invalid
+3 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ support-files = [
  "file_bug293347xslt.xml",
  "file_bug343870.xml",
  "file_bug691215.xml",
  "file_bug1666613.xml",
]

["test_bug232004.xhtml"]
@@ -19,3 +20,5 @@ skip-if = [
  "http2",
  "http3",
]

["test_bug1666613.html"]
+45 −0
Original line number Diff line number Diff line
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for Bug 1666613</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <style>iframe { width: 90%; }</style>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1666613">Mozilla Bug 691215</a>
<p id="display"></p>
<script class="testbody" type="text/javascript">

SimpleTest.waitForExplicitFinish();

function checkDir(expected) {
  return new Promise(resolve => {
    let iframe = document.createElement("iframe");
    document.body.append(iframe);
    iframe.onload = () => {
      let parserError = iframe.contentDocument.documentElement;
      is(parserError.getAttribute("dir"), expected);
      resolve();
    };
    iframe.src = "file_bug1666613.xml";
  });
}

async function sanityTest() {
  await checkDir("ltr");
  await pseudoBidiTest();
}

async function pseudoBidiTest() {
  await SpecialPowers.pushPrefEnv({
    set: [["intl.l10n.pseudo", "bidi"]]
  });
  await checkDir("rtl"); 
  SimpleTest.finish();
}

sanityTest();
</script>
</body>
</html>
+5 −0
Original line number Diff line number Diff line
@@ -434,6 +434,10 @@ parsererror|parsererror {
  color: black;
}

parsererror|parsererror[dir="rtl"] {
  direction: rtl;
}

parsererror|sourcetext {
  display: block;
  white-space: pre;
@@ -443,6 +447,7 @@ parsererror|sourcetext {
  color: red;
  font-weight: bold;
  font-size: 12pt;
  direction: ltr;
}

/* Custom content container in the CanvasFrame, positioned on top of everything