Comparing version
@@ -18,3 +18,3 @@ "use strict"; | ||
constructor(inputString) { | ||
this._input = inputString.replace(/\r\n/g, '\n'); | ||
this._input = inputString; | ||
this._offset = 0; | ||
@@ -246,3 +246,3 @@ } | ||
function isWhitespace(char) { | ||
return [' ', '\t', '\n'].indexOf(char) != -1; | ||
return [' ', '\t', '\r', '\n'].indexOf(char) != -1; | ||
} | ||
@@ -249,0 +249,0 @@ |
{ | ||
"name": "kvparser", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Parses VDF/KeyValues, used Steam and Source engine games", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -60,6 +60,2 @@ # KeyValues/VDF Parser | ||
Prior to decoding, all CRLF sequences (Windows-style line endings) are converted into LF (Unix-style line endings). | ||
Because VDF strings may contain newlines, this means that any string which contains a Windows-style newline will be | ||
converted to Unix-style newlines. | ||
Escape sequences are supported in quoted strings. Any backslash characters inside a quoted string are removed, and the | ||
@@ -66,0 +62,0 @@ following character is rendered as-is. Here are some example escape sequences and what they parse into: |
@@ -14,4 +14,4 @@ "use strict"; | ||
let test01 = parseFile('test01.vdf'); | ||
assert.deepStrictEqual(test01, { | ||
let test01crlf = parseFile('test01.eol-crlf.vdf'); | ||
assert.deepStrictEqual(test01crlf, { | ||
UnquotedRoot: { | ||
@@ -24,2 +24,3 @@ Unquoted_Key: 'Unquoted_Value_After_Spaces', | ||
QuotedKeyWithoutWhitespace: 'Quoted value that ends with escaped backslash\\', | ||
'value with newline': 'This value has a new line in it\r\nthis is the next line', | ||
SubObject: { | ||
@@ -33,2 +34,20 @@ Hello: 'World', | ||
let test01lf = parseFile('test01.eol-lf.vdf'); | ||
assert.deepStrictEqual(test01lf, { | ||
UnquotedRoot: { | ||
Unquoted_Key: 'Unquoted_Value_After_Spaces', | ||
Unquoted_Key_2: 'Unquoted_Value_After_Tabs', | ||
Unquoted_Key_3: 'Unquoted_Value_After_Single_Space', | ||
'Quoted Key 1': 'Quoted Value 1', | ||
'Quoted key with "nested" quotes': 'Quoted value with "C:\\Some\\Path\\To\\Some\\File.txt"', | ||
QuotedKeyWithoutWhitespace: 'Quoted value that ends with escaped backslash\\', | ||
'value with newline': 'This value has a new line in it\nthis is the next line', | ||
SubObject: { | ||
Hello: 'World', | ||
'This is': 'A sub-object', | ||
'Sub Object 3, this one is empty': {} | ||
} | ||
} | ||
}); | ||
assert.throws(() => parseFile('test02.vdf'), validateError(new Error('Unexpected end of input'))); | ||
@@ -35,0 +54,0 @@ |
599117
0.23%26
8.33%8031
0.22%66
-5.71%