Skip to content

Commit

Permalink
Merge pull request #4 from steveukx/issue3_newLineCharacters
Browse files Browse the repository at this point in the history
Escaped carriage returns / new lines

Closes #4
  • Loading branch information
steveukx committed Nov 17, 2014
2 parents 0a83992 + 94d224c commit 0ad62e2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "properties-reader",
"description": "Properties file reader for Node.js",
"version": "0.0.6",
"version": "0.0.7",
"author": {
"name": "Steve King",
"email": "steve@mydev.co"
Expand Down
6 changes: 6 additions & 0 deletions src/PropertiesReader.js
Expand Up @@ -96,6 +96,12 @@
else if (value === 'true' || value === 'false') {
parsedValue = (value === 'true');
}
else {
var replacements = {'\\n': '\n', '\\r': '\r', '\\t': '\t'};
parsedValue = value.replace(/\\[nrt]/g, function (key) {
return replacements[key];
});
}

return parsedValue;
};
Expand Down
12 changes: 12 additions & 0 deletions test/readerTest.js
Expand Up @@ -103,5 +103,17 @@ module.exports = new TestCase("Reader", {
Assertions.assert(app.set.withArgs('properties', properties).calledOnce, 'The complete properties object should be set as "properties"');
Assertions.assert(app.set.withArgs('some.property', 'Value').calledOnce, 'Sets all properties');
Assertions.assert(app.set.withArgs('foo.bar', 'A Value').calledOnce, 'Sets all properties');
},

'test Permits escaped new line characters': function () {
var properties = givenFilePropertiesReader('\n\nsome.property= Multi\\n Line \\nString \nfoo.bar = A Value');

// parsed access modifies the new line characters
Assertions.assertEquals(properties.get('foo.bar'), 'A Value', 'Sets all properties');
Assertions.assertEquals(properties.get('some.property'), 'Multi\n Line \nString', 'Sets all properties');

// raw access does not modify the new line characters
Assertions.assertEquals(properties.getRaw('some.property'), 'Multi\\n Line \\nString', 'Sets all properties');
Assertions.assertEquals(properties.path().some.property, 'Multi\\n Line \\nString', 'Sets all properties');
}
});

0 comments on commit 0ad62e2

Please sign in to comment.