Expanded error statements for malformed quoted text (#409)
* Emit error statements for malformed quoted text
Update parser to emit errors when strings do not adhere to section 2.2
and 2.3 of RFC 4180. Test cases are added to further support.
pull/411/head
Nic Colgrove8 years agocommitted bySergi Almacellas Abellana
nextDelim=input.indexOf(delim,cursor);// because we may have skipped the nextDelim in the quoted field
@ -1308,6 +1309,20 @@
@@ -1308,6 +1309,20 @@
break;
}
// Checks for valid closing quotes are complete (escaped quotes or quote followed by EOF/delimiter/newline) -- assume these quotes are part of an invalid text string
errors.push({
type:'Quotes',
code:'InvalidQuotes',
message:'Trailing quote on quoted field is malformed',
@ -195,6 +195,123 @@ var CORE_PARSER_TESTS = [
@@ -195,6 +195,123 @@ var CORE_PARSER_TESTS = [
}]
}
},
{
description:"Quoted field has invalid trailing quote after delimiter with a valid closer",
input:'"a,"b,c"\nd,e,f',
notes:"The input is malformed, opening quotes identified, trailing quote is malformed. Trailing quote should be escaped or followed by valid new line or delimiter to be valid",
expected:{
data:[['a,"b,c'],['d','e','f']],
errors:[{
"type":"Quotes",
"code":"InvalidQuotes",
"message":"Trailing quote on quoted field is malformed",
"row":0,
"index":1
}]
}
},
{
description:"Quoted field has invalid trailing quote after delimiter",
input:'a,"b,"c\nd,e,f',
notes:"The input is malformed, opening quotes identified, trailing quote is malformed. Trailing quote should be escaped or followed by valid new line or delimiter to be valid",
expected:{
data:[['a','b,"c\nd,e,f']],
errors:[{
"type":"Quotes",
"code":"InvalidQuotes",
"message":"Trailing quote on quoted field is malformed",
"row":0,
"index":3
},
{
"type":"Quotes",
"code":"MissingQuotes",
"message":"Quoted field unterminated",
"row":0,
"index":3
}]
}
},
{
description:"Quoted field has invalid trailing quote before delimiter",
input:'a,"b"c,d\ne,f,g',
notes:"The input is malformed, opening quotes identified, trailing quote is malformed. Trailing quote should be escaped or followed by valid new line or delimiter to be valid",
expected:{
data:[['a','b"c,d\ne,f,g']],
errors:[{
"type":"Quotes",
"code":"InvalidQuotes",
"message":"Trailing quote on quoted field is malformed",
"row":0,
"index":3
},
{
"type":"Quotes",
"code":"MissingQuotes",
"message":"Quoted field unterminated",
"row":0,
"index":3
}]
}
},
{
description:"Quoted field has invalid trailing quote after new line",
input:'a,"b,c\nd"e,f,g',
notes:"The input is malformed, opening quotes identified, trailing quote is malformed. Trailing quote should be escaped or followed by valid new line or delimiter to be valid",
expected:{
data:[['a','b,c\nd"e,f,g']],
errors:[{
"type":"Quotes",
"code":"InvalidQuotes",
"message":"Trailing quote on quoted field is malformed",
"row":0,
"index":3
},
{
"type":"Quotes",
"code":"MissingQuotes",
"message":"Quoted field unterminated",
"row":0,
"index":3
}]
}
},
{
description:"Quoted field has valid trailing quote via delimiter",
input:'a,"b",c\nd,e,f',
notes:"Trailing quote is valid due to trailing delimiter",
expected:{
data:[['a','b','c'],['d','e','f']],
errors:[]
}
},
{
description:"Quoted field has valid trailing quote via \\n",
input:'a,b,"c"\nd,e,f',
notes:"Trailing quote is valid due to trailing new line delimiter",
expected:{
data:[['a','b','c'],['d','e','f']],
errors:[]
}
},
{
description:"Quoted field has valid trailing quote via EOF",
input:'a,b,c\nd,e,"f"',
notes:"Trailing quote is valid due to EOF",
expected:{
data:[['a','b','c'],['d','e','f']],
errors:[]
}
},
{
description:"Quoted field contains delimiters and \\n with valid trailing quote",
input:'a,"b,c\nd,e,f"',
notes:"Trailing quote is valid due to trailing delimiter",