diff --git a/modules/database/src/ioc/dbStatic/dbLex.l b/modules/database/src/ioc/dbStatic/dbLex.l index 4d961975b..33185133c 100644 --- a/modules/database/src/ioc/dbStatic/dbLex.l +++ b/modules/database/src/ioc/dbStatic/dbLex.l @@ -10,6 +10,7 @@ newline "\n" backslash "\\" +singlequote "'" doublequote "\"" comment "#" whitespace [ \t\r\n] @@ -18,14 +19,17 @@ stringchar [^"\n\\] bareword [a-zA-Z0-9_\-+:.\[\]<>;] punctuation [:,\[\]{}] -normalchar [^"\\\0-\x1f] +normalchar [^"'\\\0-\x1f] barechar [a-zA-Z0-9_\-+.] escapedchar ({backslash}[^ux1-9]) hexdigit [0-9a-fA-F] latinchar ({backslash}"x"{hexdigit}{2}) unicodechar ({backslash}"u"{hexdigit}{4}) -jsonchar ({normalchar}|{escapedchar}|{latinchar}|{unicodechar}) -jsondqstr ({doublequote}{jsonchar}*{doublequote}) +jsondqchar ({normalchar}|{singlequote}|{escapedchar}|{latinchar}|{unicodechar}) +jsondqstr ({doublequote}{jsondqchar}*{doublequote}) +jsonsqchar ({normalchar}|{doublequote}|{escapedchar}|{latinchar}|{unicodechar}) +jsonsqstr ({singlequote}{jsonsqchar}*{singlequote}) +jsonstr ({jsondqstr}|{jsonsqstr}) sign ([+-]?) int ({sign}([0-9]|[1-9][0-9]+)) @@ -107,7 +111,7 @@ static int yyreset(void) {punctuation} return yytext[0]; -{jsondqstr} { +{jsonstr} { yylval.Str = dbmfStrdup((char *) yytext); return jsonSTRING; } diff --git a/modules/database/src/ioc/dbStatic/dbLexRoutines.c b/modules/database/src/ioc/dbStatic/dbLexRoutines.c index 1ec804441..ade66e347 100644 --- a/modules/database/src/ioc/dbStatic/dbLexRoutines.c +++ b/modules/database/src/ioc/dbStatic/dbLexRoutines.c @@ -1173,7 +1173,7 @@ static void dbRecordField(char *name,char *value) return; } - if (*value == '"') { + if (*value == '"' || *value == '\'') { /* jsonSTRING values still have their quotes */ value++; value[strlen(value) - 1] = 0; @@ -1206,7 +1206,7 @@ static void dbRecordInfo(char *name, char *value) ptempListNode = (tempListNode *)ellFirst(&tempList); pdbentry = ptempListNode->item; - if (*value == '"') { + if (*value == '"' || *value == '\'') { /* jsonSTRING values still have their quotes */ value++; value[strlen(value) - 1] = 0; diff --git a/modules/database/test/ioc/db/dbPutLinkTest.c b/modules/database/test/ioc/db/dbPutLinkTest.c index 830d37f6c..a1b45c8fc 100644 --- a/modules/database/test/ioc/db/dbPutLinkTest.c +++ b/modules/database/test/ioc/db/dbPutLinkTest.c @@ -67,6 +67,7 @@ static const struct testParseDataT { {" #B111 C112 N113 @cparam", {CAMAC_IO, "cparam", 0, "BCN", {111, 112, 113}}}, {" @hello world ", {INST_IO, "hello world", 0, "", /*{}*/}}, {" {\"x\":true} ", {JSON_LINK, "{\"x\":true}", 0, "", /*{}*/}}, + {" {'x':true} ", {JSON_LINK, "{'x':true}", 0, "", /*{}*/}}, {NULL} }; @@ -587,7 +588,9 @@ void testJLink(void) testdbGetFieldEqual("j1.INP", DBF_STRING, "{z:{good:1}}"); testdbGetFieldEqual("j1.VAL", DBF_LONG, 1); + testdbGetFieldEqual("j2.INP", DBF_STRING, "{\"z\":{'good':2}}"); testdbGetFieldEqual("j2.VAL", DBF_LONG, 2); + testdbGetFieldEqual("j2.TSEL", DBF_STRING, "j1.TIME NPP NMS"); testdbGetFieldEqual("j3.VAL", DBF_LONG, 3); testNumZ(6); @@ -596,7 +599,7 @@ void testJLink(void) testdbPutFieldOk("j1.PROC", DBF_LONG, 1); testdbGetFieldEqual("j1.VAL", DBF_LONG, 4); - testdbPutFieldOk("j2.TSEL", DBF_STRING, "{\"z\":{\"good\":0}}"); + testdbPutFieldOk("j2.TSEL", DBF_STRING, "{'z':{good:0}}"); testdbPutFieldOk("j2.PROC", DBF_LONG, 1); testNumZ(7); @@ -611,8 +614,8 @@ void testJLink(void) testNumZ(7); /* Check SDIS using a JSON link prevents processing */ - testdbPutFieldOk("j1.SDIS", DBF_STRING, "{\"z\":{\"good\":1}}"); - testdbPutFieldOk("j1.INP", DBF_STRING, "{\"z\":{\"good\":1}}"); + testdbPutFieldOk("j1.SDIS", DBF_STRING, "{z:{good:1}}"); + testdbPutFieldOk("j1.INP", DBF_STRING, "{z:{good:1}}"); testdbPutFieldOk("j1.PROC", DBF_LONG, 1); testdbGetFieldEqual("j1.VAL", DBF_LONG, 4); @@ -697,7 +700,7 @@ void testTSEL(void) MAIN(dbPutLinkTest) { - testPlan(337); + testPlan(342); testLinkParse(); testLinkFailParse(); testCADBSet(); diff --git a/modules/database/test/ioc/db/dbPutLinkTestJ.db b/modules/database/test/ioc/db/dbPutLinkTestJ.db index 621557c2c..4f518c50f 100644 --- a/modules/database/test/ioc/db/dbPutLinkTestJ.db +++ b/modules/database/test/ioc/db/dbPutLinkTestJ.db @@ -7,8 +7,8 @@ record(x, "j1") { } record(x, "j2") { - field(INP, {z:{good:2}}) - field(TSEL, "j1.TIME") + field(INP, {"z":{'good':2}}) + field(TSEL, 'j1.TIME') } record(x, "j3") {