mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-14 15:24:52 +09:00
Ignore BOM in locale files
Ignore BOM at the start of Factorio locale files as this is a thing Factorio also does. Fixes #507
This commit is contained in:
1 parent
6eda1f78d5
commit
f23e442c4c
3 files changed
+14
No files matched your search
@@ -11,6 +11,11 @@
|
||||
* @returns sections parsed from the ini file.
|
||||
*/
|
||||
export function parse(input: string) {
|
||||
// Ignore BOM at the start of the file
|
||||
if (input[0] === "\uFEFF") {
|
||||
input = input.slice(1);
|
||||
}
|
||||
|
||||
const sections: Record<string, string | Record<string, string>> = {};
|
||||
let currentSection: Record<string, string> = sections as Record<string, string>;
|
||||
const lines = input.split(/\r\n|\n/);
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
[spam]
|
||||
foo=bar
|
||||
@@ -1,5 +1,6 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const fs = require("fs-extra");
|
||||
const lib = require("@clusterio/lib");
|
||||
|
||||
describe("lib/ini", function() {
|
||||
@@ -58,6 +59,12 @@ describe("lib/ini", function() {
|
||||
new Error("Duplicated key key on line 2")
|
||||
);
|
||||
});
|
||||
it("should parse a file with BOM", async function() {
|
||||
assert.deepEqual(
|
||||
lib.parse(await fs.readFile("test/file/bom.cfg", "utf8")),
|
||||
{ spam: { foo: "bar" }},
|
||||
);
|
||||
});
|
||||
});
|
||||
describe("stringify()", function() {
|
||||
it("should serialize to reference output", function() {
|
||||
|
||||
Reference in new issue
Block a user