From bec433512858ab4f07b167261b127a62a04150fd Mon Sep 17 00:00:00 2001 From: Tim Abraldes Date: Wed, 23 May 2012 10:09:10 -0700 Subject: [PATCH] bug 752756. Read UTF-16le and UTF-8 BOMs in nsINIParser on Windows. Add parameter to nsIINIParserWriter::writeFile() specifying the charset of the file (BOM will be written). r=bsmedberg --- toolkit/crashreporter/nsExceptionHandler.cpp | 2 +- xpcom/ds/nsIINIParser.idl | 12 ++- xpcom/ds/nsINIProcessor.js | 39 ++++++-- xpcom/glue/nsINIParser.cpp | 62 +++++++++++-- .../unit/data/iniparser01-utf16leBOM.ini | 1 + xpcom/tests/unit/data/iniparser01-utf8BOM.ini | 1 + .../unit/data/iniparser02-utf16leBOM.ini | Bin 0 -> 6 bytes xpcom/tests/unit/data/iniparser02-utf8BOM.ini | 1 + .../unit/data/iniparser03-utf16leBOM.ini | Bin 0 -> 10 bytes xpcom/tests/unit/data/iniparser03-utf8BOM.ini | 1 + .../unit/data/iniparser04-utf16leBOM.ini | Bin 0 -> 26 bytes xpcom/tests/unit/data/iniparser04-utf8BOM.ini | 1 + .../unit/data/iniparser05-utf16leBOM.ini | Bin 0 -> 34 bytes xpcom/tests/unit/data/iniparser05-utf8BOM.ini | 1 + .../unit/data/iniparser06-utf16leBOM.ini | Bin 0 -> 30 bytes xpcom/tests/unit/data/iniparser06-utf8BOM.ini | 2 + .../unit/data/iniparser07-utf16leBOM.ini | Bin 0 -> 40 bytes xpcom/tests/unit/data/iniparser07-utf8BOM.ini | 2 + .../unit/data/iniparser08-utf16leBOM.ini | Bin 0 -> 42 bytes xpcom/tests/unit/data/iniparser08-utf8BOM.ini | 2 + .../unit/data/iniparser09-utf16leBOM.ini | Bin 0 -> 54 bytes xpcom/tests/unit/data/iniparser09-utf8BOM.ini | 2 + .../unit/data/iniparser10-utf16leBOM.ini | Bin 0 -> 58 bytes xpcom/tests/unit/data/iniparser10-utf8BOM.ini | 3 + .../unit/data/iniparser11-utf16leBOM.ini | Bin 0 -> 76 bytes xpcom/tests/unit/data/iniparser11-utf8BOM.ini | 3 + .../unit/data/iniparser12-utf16leBOM.ini | Bin 0 -> 86 bytes xpcom/tests/unit/data/iniparser12-utf8BOM.ini | 3 + .../unit/data/iniparser13-utf16leBOM.ini | Bin 0 -> 94 bytes xpcom/tests/unit/data/iniparser13-utf8BOM.ini | 3 + .../unit/data/iniparser14-utf16leBOM.ini | Bin 0 -> 160 bytes xpcom/tests/unit/data/iniparser14-utf8BOM.ini | 6 ++ .../unit/data/iniparser15-utf16leBOM.ini | Bin 0 -> 162 bytes xpcom/tests/unit/data/iniparser15-utf8BOM.ini | 6 ++ .../unit/data/iniparser16-utf16leBOM.ini | Bin 0 -> 210 bytes xpcom/tests/unit/data/iniparser16-utf8BOM.ini | 13 +++ xpcom/tests/unit/data/iniparser16.ini | 13 +++ xpcom/tests/unit/test_iniProcessor.js | 87 ++++++++++++++++-- 38 files changed, 240 insertions(+), 26 deletions(-) create mode 100644 xpcom/tests/unit/data/iniparser01-utf16leBOM.ini create mode 100644 xpcom/tests/unit/data/iniparser01-utf8BOM.ini create mode 100644 xpcom/tests/unit/data/iniparser02-utf16leBOM.ini create mode 100644 xpcom/tests/unit/data/iniparser02-utf8BOM.ini create mode 100644 xpcom/tests/unit/data/iniparser03-utf16leBOM.ini create mode 100644 xpcom/tests/unit/data/iniparser03-utf8BOM.ini create mode 100644 xpcom/tests/unit/data/iniparser04-utf16leBOM.ini create mode 100644 xpcom/tests/unit/data/iniparser04-utf8BOM.ini create mode 100644 xpcom/tests/unit/data/iniparser05-utf16leBOM.ini create mode 100644 xpcom/tests/unit/data/iniparser05-utf8BOM.ini create mode 100644 xpcom/tests/unit/data/iniparser06-utf16leBOM.ini create mode 100644 xpcom/tests/unit/data/iniparser06-utf8BOM.ini create mode 100644 xpcom/tests/unit/data/iniparser07-utf16leBOM.ini create mode 100644 xpcom/tests/unit/data/iniparser07-utf8BOM.ini create mode 100644 xpcom/tests/unit/data/iniparser08-utf16leBOM.ini create mode 100644 xpcom/tests/unit/data/iniparser08-utf8BOM.ini create mode 100644 xpcom/tests/unit/data/iniparser09-utf16leBOM.ini create mode 100644 xpcom/tests/unit/data/iniparser09-utf8BOM.ini create mode 100644 xpcom/tests/unit/data/iniparser10-utf16leBOM.ini create mode 100644 xpcom/tests/unit/data/iniparser10-utf8BOM.ini create mode 100644 xpcom/tests/unit/data/iniparser11-utf16leBOM.ini create mode 100644 xpcom/tests/unit/data/iniparser11-utf8BOM.ini create mode 100644 xpcom/tests/unit/data/iniparser12-utf16leBOM.ini create mode 100644 xpcom/tests/unit/data/iniparser12-utf8BOM.ini create mode 100644 xpcom/tests/unit/data/iniparser13-utf16leBOM.ini create mode 100644 xpcom/tests/unit/data/iniparser13-utf8BOM.ini create mode 100644 xpcom/tests/unit/data/iniparser14-utf16leBOM.ini create mode 100644 xpcom/tests/unit/data/iniparser14-utf8BOM.ini create mode 100644 xpcom/tests/unit/data/iniparser15-utf16leBOM.ini create mode 100644 xpcom/tests/unit/data/iniparser15-utf8BOM.ini create mode 100644 xpcom/tests/unit/data/iniparser16-utf16leBOM.ini create mode 100644 xpcom/tests/unit/data/iniparser16-utf8BOM.ini create mode 100644 xpcom/tests/unit/data/iniparser16.ini diff --git a/toolkit/crashreporter/nsExceptionHandler.cpp b/toolkit/crashreporter/nsExceptionHandler.cpp index b7c5ddd550b..f1f8b2c6b8f 100644 --- a/toolkit/crashreporter/nsExceptionHandler.cpp +++ b/toolkit/crashreporter/nsExceptionHandler.cpp @@ -1589,7 +1589,7 @@ static nsresult PrefSubmitReports(bool* aSubmitReports, bool writePref) *aSubmitReports ? NS_LITERAL_CSTRING("1") : NS_LITERAL_CSTRING("0")); NS_ENSURE_SUCCESS(rv, rv); - rv = iniWriter->WriteFile(NULL); + rv = iniWriter->WriteFile(NULL, 0); return rv; } diff --git a/xpcom/ds/nsIINIParser.idl b/xpcom/ds/nsIINIParser.idl index 2d0be551184..453ae8a01f9 100644 --- a/xpcom/ds/nsIINIParser.idl +++ b/xpcom/ds/nsIINIParser.idl @@ -26,9 +26,16 @@ interface nsIINIParser : nsISupports AUTF8String getString(in AUTF8String aSection, in AUTF8String aKey); }; -[scriptable, uuid(712dc5da-8d09-45d0-ba2e-de27eb384c4c)] +[scriptable, uuid(b67bb24b-31a3-4a6a-a5d9-0485c9af5a04)] interface nsIINIParserWriter : nsISupports { + /** + * Windows and the NSIS installer code sometimes expect INI files to be in + * UTF-16 encoding. On Windows only, this flag to writeFile can be used to + * change the encoding from its default UTF-8. + */ + const unsigned long WRITE_UTF16 = 0x1; + /** * Set the value of a string for a particular section and key. */ @@ -37,7 +44,8 @@ interface nsIINIParserWriter : nsISupports /** * Write to the INI file. */ - void writeFile([optional] in nsILocalFile aINIFile); + void writeFile([optional] in nsILocalFile aINIFile, + [optional] in unsigned long aFlags); }; [scriptable, uuid(ccae7ea5-1218-4b51-aecb-c2d8ecd46af9)] diff --git a/xpcom/ds/nsINIProcessor.js b/xpcom/ds/nsINIProcessor.js index 499f57e0792..2c391eb5bad 100644 --- a/xpcom/ds/nsINIProcessor.js +++ b/xpcom/ds/nsINIProcessor.js @@ -37,18 +37,29 @@ function INIProcessor(aFile) { INIProcessor.prototype = { QueryInterface : XPCOMUtils.generateQI([Ci.nsIINIParser, Ci.nsIINIParserWriter]), - __utfConverter : null, // UCS2 <--> UTF8 string conversion - get _utfConverter() { - if (!this.__utfConverter) { - this.__utfConverter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]. + __utf8Converter : null, // UCS2 <--> UTF8 string conversion + get _utf8Converter() { + if (!this.__utf8Converter) { + this.__utf8Converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]. createInstance(Ci.nsIScriptableUnicodeConverter); - this.__utfConverter.charset = "UTF-8"; + this.__utf8Converter.charset = "UTF-8"; } - return this.__utfConverter; + return this.__utf8Converter; + }, + + __utf16leConverter : null, // UCS2 <--> UTF16LE string conversion + get _utf16leConverter() { + if (!this.__utf16leConverter) { + this.__utf16leConverter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]. + createInstance(Ci.nsIScriptableUnicodeConverter); + this.__utf16leConverter.charset = "UTF-16LE"; + } + return this.__utf16leConverter; }, _utfConverterReset : function() { - this.__utfConverter = null; + this.__utf8Converter = null; + this.__utf16leConverter = null; }, _iniFile : null, @@ -117,13 +128,13 @@ INIProcessor.prototype = { this._iniData[aSection][aKey] = aValue; }, - writeFile : function(aFile) { + writeFile : function(aFile, aFlags) { - let converter = this._utfConverter; + let converter; function writeLine(data) { + data += "\n"; data = converter.ConvertFromUnicode(data); data += converter.Finish(); - data += "\n"; outputStream.write(data, data.length); } @@ -140,6 +151,14 @@ INIProcessor.prototype = { outputStream.init(safeStream, 8192); outputStream.QueryInterface(Ci.nsISafeOutputStream); // for .finish() + if (Ci.nsIINIParserWriter.WRITE_UTF16 == aFlags + && 'nsIWindowsRegKey' in Ci) { + outputStream.write("\xFF\xFE", 2); + converter = this._utf16leConverter; + } else { + converter = this._utf8Converter; + } + for (let section in this._iniData) { writeLine("[" + section + "]"); for (let key in this._iniData[section]) { diff --git a/xpcom/glue/nsINIParser.cpp b/xpcom/glue/nsINIParser.cpp index 7397fafb813..5a07756bd89 100644 --- a/xpcom/glue/nsINIParser.cpp +++ b/xpcom/glue/nsINIParser.cpp @@ -3,13 +3,16 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "nsINIParser.h" +// Moz headers (alphabetical) +#include "nsCRTGlue.h" #include "nsError.h" #include "nsILocalFile.h" -#include "nsCRTGlue.h" +#include "nsINIParser.h" +#include "mozilla/FileUtils.h" // AutoFILE -#include +// System headers (alphabetical) #include +#include #ifdef XP_WIN #include #endif @@ -109,7 +112,7 @@ nsINIParser::InitFromFILE(FILE *fd) return NS_ERROR_FAILURE; /* malloc an internal buf the size of the file */ - mFileContents = new char[flen + 1]; + mFileContents = new char[flen + 2]; if (!mFileContents) return NS_ERROR_OUT_OF_MEMORY; @@ -121,9 +124,56 @@ nsINIParser::InitFromFILE(FILE *fd) if (rd != flen) return NS_BASE_STREAM_OSERROR; - mFileContents[flen] = '\0'; + // We write a UTF16 null so that the file is easier to convert to UTF8 + mFileContents[flen] = mFileContents[flen + 1] = '\0'; + + char *buffer = &mFileContents[0]; + + if (flen >= 3 + && mFileContents[0] == static_cast(0xEF) + && mFileContents[1] == static_cast(0xBB) + && mFileContents[2] == static_cast(0xBF)) { + // Someone set us up the Utf-8 BOM + // This case is easy, since we assume that BOM-less + // files are Utf-8 anyway. Just skip the BOM and process as usual. + buffer = &mFileContents[3]; + } + +#ifdef XP_WIN + if (flen >= 2 + && mFileContents[0] == static_cast(0xFF) + && mFileContents[1] == static_cast(0xFE)) { + // Someone set us up the Utf-16LE BOM + buffer = &mFileContents[2]; + // Get the size required for our Utf8 buffer + flen = WideCharToMultiByte(CP_UTF8, + 0, + reinterpret_cast(buffer), + -1, + NULL, + 0, + NULL, + NULL); + if (0 == flen) { + return NS_ERROR_FAILURE; + } + + nsAutoArrayPtr utf8Buffer = new char[flen]; + if (0 == WideCharToMultiByte(CP_UTF8, + 0, + reinterpret_cast(buffer), + -1, + utf8Buffer, + flen, + NULL, + NULL)) { + return NS_ERROR_FAILURE; + } + mFileContents = utf8Buffer.forget(); + buffer = mFileContents; + } +#endif - char *buffer = mFileContents; char *currSection = nsnull; // outer loop tokenizes into lines diff --git a/xpcom/tests/unit/data/iniparser01-utf16leBOM.ini b/xpcom/tests/unit/data/iniparser01-utf16leBOM.ini new file mode 100644 index 00000000000..46b134b197f --- /dev/null +++ b/xpcom/tests/unit/data/iniparser01-utf16leBOM.ini @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/xpcom/tests/unit/data/iniparser01-utf8BOM.ini b/xpcom/tests/unit/data/iniparser01-utf8BOM.ini new file mode 100644 index 00000000000..5f282702bb0 --- /dev/null +++ b/xpcom/tests/unit/data/iniparser01-utf8BOM.ini @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/xpcom/tests/unit/data/iniparser02-utf16leBOM.ini b/xpcom/tests/unit/data/iniparser02-utf16leBOM.ini new file mode 100644 index 0000000000000000000000000000000000000000..49cc8ef0e116cef009fe0bd72473a964bbd07f9b GIT binary patch literal 6 NcmezWkC%aq0RRg=0u=xN literal 0 HcmV?d00001 diff --git a/xpcom/tests/unit/data/iniparser02-utf8BOM.ini b/xpcom/tests/unit/data/iniparser02-utf8BOM.ini new file mode 100644 index 00000000000..e02abfc9b0e --- /dev/null +++ b/xpcom/tests/unit/data/iniparser02-utf8BOM.ini @@ -0,0 +1 @@ + diff --git a/xpcom/tests/unit/data/iniparser03-utf16leBOM.ini b/xpcom/tests/unit/data/iniparser03-utf16leBOM.ini new file mode 100644 index 0000000000000000000000000000000000000000..05255100a2c2cda1c93700bd6a850ed2ae29c95c GIT binary patch literal 10 RcmezWFPb5iftP`c0RR|00?hyb literal 0 HcmV?d00001 diff --git a/xpcom/tests/unit/data/iniparser03-utf8BOM.ini b/xpcom/tests/unit/data/iniparser03-utf8BOM.ini new file mode 100644 index 00000000000..b76e44e1949 --- /dev/null +++ b/xpcom/tests/unit/data/iniparser03-utf8BOM.ini @@ -0,0 +1 @@ +[] diff --git a/xpcom/tests/unit/data/iniparser04-utf16leBOM.ini b/xpcom/tests/unit/data/iniparser04-utf16leBOM.ini new file mode 100644 index 0000000000000000000000000000000000000000..e95d971134265cd52d7813c9d08232648b786eb0 GIT binary patch literal 26 hcmezWFPfp4A(bJSp@bomA)g_S!H^-AftP`c0RV1}1@iy^ literal 0 HcmV?d00001 diff --git a/xpcom/tests/unit/data/iniparser04-utf8BOM.ini b/xpcom/tests/unit/data/iniparser04-utf8BOM.ini new file mode 100644 index 00000000000..47ef32c0a9f --- /dev/null +++ b/xpcom/tests/unit/data/iniparser04-utf8BOM.ini @@ -0,0 +1 @@ +[section1] diff --git a/xpcom/tests/unit/data/iniparser05-utf16leBOM.ini b/xpcom/tests/unit/data/iniparser05-utf16leBOM.ini new file mode 100644 index 0000000000000000000000000000000000000000..a49491816c7f0078ed4256020b303772740a89f1 GIT binary patch literal 34 ocmezWFPfp4A(bJSp@bomA)g_S!H^-AA&a3D$jWBmW#D1}0IccvWw2iyPv literal 0 HcmV?d00001 diff --git a/xpcom/tests/unit/data/iniparser07-utf8BOM.ini b/xpcom/tests/unit/data/iniparser07-utf8BOM.ini new file mode 100644 index 00000000000..38176d9444e --- /dev/null +++ b/xpcom/tests/unit/data/iniparser07-utf8BOM.ini @@ -0,0 +1,2 @@ +[section1] +name1 diff --git a/xpcom/tests/unit/data/iniparser08-utf16leBOM.ini b/xpcom/tests/unit/data/iniparser08-utf16leBOM.ini new file mode 100644 index 0000000000000000000000000000000000000000..e450566a0f64799900c22d224e0951f8c43f4f2b GIT binary patch literal 42 rcmezWFPfp4A(bJSp@bomA)g_S!H^-AftP^`$Vz0$1**OfQU>-;g0AT$J AX8-^I literal 0 HcmV?d00001 diff --git a/xpcom/tests/unit/data/iniparser09-utf8BOM.ini b/xpcom/tests/unit/data/iniparser09-utf8BOM.ini new file mode 100644 index 00000000000..e3edce4d495 --- /dev/null +++ b/xpcom/tests/unit/data/iniparser09-utf8BOM.ini @@ -0,0 +1,2 @@ +[section1] +name1=value1 diff --git a/xpcom/tests/unit/data/iniparser10-utf16leBOM.ini b/xpcom/tests/unit/data/iniparser10-utf16leBOM.ini new file mode 100644 index 0000000000000000000000000000000000000000..e5e70b6612b3c4f16bf1b94eba4d985937cdbaee GIT binary patch literal 58 zcmezWkC%aqA)29>A(bJSp@bomA)g_S!H^-A0VJNskjRh=lrdzmWheu(a~Mj&Jdhj! DZRrYr literal 0 HcmV?d00001 diff --git a/xpcom/tests/unit/data/iniparser10-utf8BOM.ini b/xpcom/tests/unit/data/iniparser10-utf8BOM.ini new file mode 100644 index 00000000000..bda15fcc7b3 --- /dev/null +++ b/xpcom/tests/unit/data/iniparser10-utf8BOM.ini @@ -0,0 +1,3 @@ + +[section1] +name1=value1 diff --git a/xpcom/tests/unit/data/iniparser11-utf16leBOM.ini b/xpcom/tests/unit/data/iniparser11-utf16leBOM.ini new file mode 100644 index 0000000000000000000000000000000000000000..932d4004bc840990b5af2556e082b0e1adb4cef4 GIT binary patch literal 76 zcmezWPnki1A(**OfQU>-**OfQU>>rZ5sI7< WSRcB1MkJb-26RO}Ljgl2*faoZ%Nv^j literal 0 HcmV?d00001 diff --git a/xpcom/tests/unit/data/iniparser14-utf8BOM.ini b/xpcom/tests/unit/data/iniparser14-utf8BOM.ini new file mode 100644 index 00000000000..d109052c8d3 --- /dev/null +++ b/xpcom/tests/unit/data/iniparser14-utf8BOM.ini @@ -0,0 +1,6 @@ +[section1] +name1=value1 +name2=value2 +[section2] +name1=value1 +name2=foopy diff --git a/xpcom/tests/unit/data/iniparser15-utf16leBOM.ini b/xpcom/tests/unit/data/iniparser15-utf16leBOM.ini new file mode 100644 index 0000000000000000000000000000000000000000..e60525dec63c7e5de478fda81402db8a8589e59d GIT binary patch literal 162 zcmezWFPfp4A(bJSp@bomA)g_S!H^-AftP^`$Vz0$1**OfQU>-;gU5^nK cJ!wGG@)-&kD#50q>%eA99?<-9hA=d{0KDNGLjV8( literal 0 HcmV?d00001 diff --git a/xpcom/tests/unit/data/iniparser15-utf8BOM.ini b/xpcom/tests/unit/data/iniparser15-utf8BOM.ini new file mode 100644 index 00000000000..172803f90bf --- /dev/null +++ b/xpcom/tests/unit/data/iniparser15-utf8BOM.ini @@ -0,0 +1,6 @@ +[section1] +name1=value1 +[section2] +name1=foopy +[section1] +name1=newValue1 diff --git a/xpcom/tests/unit/data/iniparser16-utf16leBOM.ini b/xpcom/tests/unit/data/iniparser16-utf16leBOM.ini new file mode 100644 index 0000000000000000000000000000000000000000..142b1759022924f57c166a07f3810df459e0c9e3 GIT binary patch literal 210 zcmezWPnqGjyszA5mTS!I%mU0um=u{_FuF3XWKd(^W#D3nX0TGrR*MC*l^JSSU}`~f z*=n{7)@mS@G6Sk!kXRN_HWeystDr7lFALENQIE?u8>n5$K-~#o-D!Bu!L%0u9CIi| literal 0 HcmV?d00001 diff --git a/xpcom/tests/unit/data/iniparser16-utf8BOM.ini b/xpcom/tests/unit/data/iniparser16-utf8BOM.ini new file mode 100644 index 00000000000..bba1018daba --- /dev/null +++ b/xpcom/tests/unit/data/iniparser16-utf8BOM.ini @@ -0,0 +1,13 @@ +#Ώṍҳϖ·̐˄ȡǨŅ©& +[☺♫] +#ѼΏṍҳϖ +♫=☻ +#·̐˄ȡǨŅ© +♪=♥ +#‽ἧᵿΏṍҳ +#ϖ·̐˄ȡǨŅ©& +[☼] +♣=♠ +♦=♥ +#‽ἧᵿΏṍҳ +#·̐˄ȡǨŅ© diff --git a/xpcom/tests/unit/data/iniparser16.ini b/xpcom/tests/unit/data/iniparser16.ini new file mode 100644 index 00000000000..b94607d15d9 --- /dev/null +++ b/xpcom/tests/unit/data/iniparser16.ini @@ -0,0 +1,13 @@ +#Ώṍҳϖ·̐˄ȡǨŅ©& +[☺♫] +#ѼΏṍҳϖ +♫=☻ +#·̐˄ȡǨŅ© +♪=♥ +#‽ἧᵿΏṍҳ +#ϖ·̐˄ȡǨŅ©& +[☼] +♣=♠ +♦=♥ +#‽ἧᵿΏṍҳ +#·̐˄ȡǨŅ© diff --git a/xpcom/tests/unit/test_iniProcessor.js b/xpcom/tests/unit/test_iniProcessor.js index 866ddde5daa..a7e2477785a 100644 --- a/xpcom/tests/unit/test_iniProcessor.js +++ b/xpcom/tests/unit/test_iniProcessor.js @@ -90,20 +90,93 @@ let testdata = [ { filename: "data/iniparser15.ini", reference: { section1: { name1: "newValue1" }, section2: { name1: "foopy" }} }, + { filename: "data/iniparser16.ini", reference: + { "☺♫": { "♫": "☻", "♪": "♥" }, + "☼": { "♣": "♠", "♦": "♥" }} }, + ]; + testdata.push( { filename: "data/iniparser01-utf8BOM.ini", + reference: testdata[0].reference } ); + testdata.push( { filename: "data/iniparser02-utf8BOM.ini", + reference: testdata[1].reference } ); + testdata.push( { filename: "data/iniparser03-utf8BOM.ini", + reference: testdata[2].reference } ); + testdata.push( { filename: "data/iniparser04-utf8BOM.ini", + reference: testdata[3].reference } ); + testdata.push( { filename: "data/iniparser05-utf8BOM.ini", + reference: testdata[4].reference } ); + testdata.push( { filename: "data/iniparser06-utf8BOM.ini", + reference: testdata[5].reference } ); + testdata.push( { filename: "data/iniparser07-utf8BOM.ini", + reference: testdata[6].reference } ); + testdata.push( { filename: "data/iniparser08-utf8BOM.ini", + reference: testdata[7].reference } ); + testdata.push( { filename: "data/iniparser09-utf8BOM.ini", + reference: testdata[8].reference } ); + testdata.push( { filename: "data/iniparser10-utf8BOM.ini", + reference: testdata[9].reference } ); + testdata.push( { filename: "data/iniparser11-utf8BOM.ini", + reference: testdata[10].reference } ); + testdata.push( { filename: "data/iniparser12-utf8BOM.ini", + reference: testdata[11].reference } ); + testdata.push( { filename: "data/iniparser13-utf8BOM.ini", + reference: testdata[12].reference } ); + testdata.push( { filename: "data/iniparser14-utf8BOM.ini", + reference: testdata[13].reference } ); + testdata.push( { filename: "data/iniparser15-utf8BOM.ini", + reference: testdata[14].reference } ); + testdata.push( { filename: "data/iniparser16-utf8BOM.ini", + reference: testdata[15].reference } ); + + let os = Cc["@mozilla.org/xre/app-info;1"] + .getService(Ci.nsIXULRuntime).OS; + if("WINNT" === os) { + testdata.push( { filename: "data/iniparser01-utf16leBOM.ini", + reference: testdata[0].reference } ); + testdata.push( { filename: "data/iniparser02-utf16leBOM.ini", + reference: testdata[1].reference } ); + testdata.push( { filename: "data/iniparser03-utf16leBOM.ini", + reference: testdata[2].reference } ); + testdata.push( { filename: "data/iniparser04-utf16leBOM.ini", + reference: testdata[3].reference } ); + testdata.push( { filename: "data/iniparser05-utf16leBOM.ini", + reference: testdata[4].reference } ); + testdata.push( { filename: "data/iniparser06-utf16leBOM.ini", + reference: testdata[5].reference } ); + testdata.push( { filename: "data/iniparser07-utf16leBOM.ini", + reference: testdata[6].reference } ); + testdata.push( { filename: "data/iniparser08-utf16leBOM.ini", + reference: testdata[7].reference } ); + testdata.push( { filename: "data/iniparser09-utf16leBOM.ini", + reference: testdata[8].reference } ); + testdata.push( { filename: "data/iniparser10-utf16leBOM.ini", + reference: testdata[9].reference } ); + testdata.push( { filename: "data/iniparser11-utf16leBOM.ini", + reference: testdata[10].reference } ); + testdata.push( { filename: "data/iniparser12-utf16leBOM.ini", + reference: testdata[11].reference } ); + testdata.push( { filename: "data/iniparser13-utf16leBOM.ini", + reference: testdata[12].reference } ); + testdata.push( { filename: "data/iniparser14-utf16leBOM.ini", + reference: testdata[13].reference } ); + testdata.push( { filename: "data/iniparser15-utf16leBOM.ini", + reference: testdata[14].reference } ); + testdata.push( { filename: "data/iniparser16-utf16leBOM.ini", + reference: testdata[15].reference } ); + } + /* ========== 0 ========== */ factory = Cc["@mozilla.org/xpcom/ini-processor-factory;1"]. getService(Ci.nsIINIParserFactory); do_check_true(!!factory); -/* ========== 1 - 15 ========== */ - // Test reading from a variety of files. While we're at it, write out each one // and read it back to ensure that nothing changed. -for (testnum = 1; testnum <= 15; testnum++) { +while (testnum < testdata.length) { + dump("\nINFO | test #" + ++testnum); let filename = testdata[testnum -1].filename; - dump("INFO | test #" + testnum + ", filename " + filename + "\n"); + dump(", filename " + filename + "\n"); let parser = parserForFile(filename); checkParserOutput(parser, testdata[testnum - 1].reference); if (!parser) @@ -121,7 +194,7 @@ for (testnum = 1; testnum <= 15; testnum++) { newfile.remove(false); } -/* ========== 16 ========== */ +dump("INFO | test #" + ++testnum + "\n"); // test writing to a new file. let newfile = do_get_file("data/"); @@ -148,7 +221,7 @@ checkParserOutput(parser, {section: {key: "value"} }); // cleanup after the test newfile.remove(false); -/* ========== 17 ========== */ +dump("INFO | test #" + ++testnum + "\n"); // test modifying a existing key's value (in an existing section) parser = parserForFile("data/iniparser09.ini"); @@ -158,7 +231,7 @@ do_check_true(parser instanceof Ci.nsIINIParserWriter); parser.setString("section1", "name1", "value2"); checkParserOutput(parser, {section1: {name1: "value2"} }); -/* ========== 18 ========== */ +dump("INFO | test #" + ++testnum + "\n"); // test trying to set illegal characters let caughtError;