From 8a41f6bd151e82eed8359195a9ac07201de08d1d Mon Sep 17 00:00:00 2001 From: Neil Deakin Date: Fri, 21 Aug 2015 13:30:04 -0400 Subject: [PATCH] Bug 1195931, use option.text instead of option.textContent so that spaces get handled properly in select lists, r=felipe --- .../test/general/browser_selectpopup.js | 18 +++++++++++------- toolkit/modules/SelectContentHelper.jsm | 9 +++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/browser/base/content/test/general/browser_selectpopup.js b/browser/base/content/test/general/browser_selectpopup.js index 253bc9a35ff7..6e043d9139d6 100644 --- a/browser/base/content/test/general/browser_selectpopup.js +++ b/browser/base/content/test/general/browser_selectpopup.js @@ -5,6 +5,8 @@ // in a child process. This is different than single-process as a is used // to implement the dropdown list. +const XHTML_DTD = ''; + const PAGECONTENT = "" + "" + ""; @@ -58,11 +60,11 @@ function getChangeEvents() }); } -function doSelectTests(contentType) +function doSelectTests(contentType, dtd) { let tab = gBrowser.selectedTab = gBrowser.addTab(); let browser = gBrowser.getBrowserForTab(tab); - yield promiseTabLoadEvent(tab, "data:" + contentType + "," + escape(PAGECONTENT)); + yield promiseTabLoadEvent(tab, "data:" + contentType + "," + escape(dtd + "\n" + PAGECONTENT)); yield SimpleTest.promiseFocus(browser.contentWindow); @@ -127,15 +129,17 @@ function doSelectTests(contentType) EventUtils.synthesizeKey("VK_TAB", { shiftKey: true }); is((yield getChangeEvents()), isWindows ? 2 : 1, "Tab away from select with change - number of change events"); + is(selectPopup.lastChild.previousSibling.label, "Seven", "Spaces collapsed"); + is(selectPopup.lastChild.label, "\xA0\xA0Eight\xA0\xA0", "Non-breaking spaces not collapsed"); + gBrowser.removeCurrentTab(); } add_task(function*() { - yield doSelectTests("text/html"); + yield doSelectTests("text/html", ""); }); add_task(function*() { - yield doSelectTests("application/xhtml+xml"); + yield doSelectTests("application/xhtml+xml", XHTML_DTD); }); - diff --git a/toolkit/modules/SelectContentHelper.jsm b/toolkit/modules/SelectContentHelper.jsm index 4bc6a781236f..fb3e0c840d56 100644 --- a/toolkit/modules/SelectContentHelper.jsm +++ b/toolkit/modules/SelectContentHelper.jsm @@ -101,12 +101,9 @@ function buildOptionListForChildren(node) { if (tagName == 'OPTION' || tagName == 'OPTGROUP') { let textContent = tagName == 'OPTGROUP' ? child.getAttribute("label") - : child.textContent; - - if (textContent != null) { - textContent = textContent.trim(); - } else { - textContent = "" + : child.text; + if (textContent == null) { + textContent = ""; } let info = {