Skip to content

Commit

Permalink
Quote boolean values when dumping strings
Browse files Browse the repository at this point in the history
  • Loading branch information
dhcole committed Jun 6, 2013
1 parent 454c7e7 commit 6830867
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/js-yaml/dumper.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,12 @@ function dump(input, options) {
}

function writeScalar(object) {
var isQuoted, checkpoint, position, length, character;
var isQuoted, checkpoint, position, length, character, booleans;

result = '';
isQuoted = false;
checkpoint = 0;
booleans = /^(y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF)$/;

if (0 === object.length ||
CHAR_SPACE === object.charCodeAt(0) ||
Expand Down Expand Up @@ -224,6 +225,10 @@ function dump(input, options) {
isQuoted = true;
}

if (!isQuoted && booleans.test(object)) {
isQuoted = true;
}

if (isQuoted) {
result = '"' + result + '"';
}
Expand Down

0 comments on commit 6830867

Please sign in to comment.