Code

CData: Fixed handling of whitespace + garbage detection at end of input.
[postrr.git] / src / cdata.c
index 26f2656acbb5d544fd644ea1bc5e70d453238401..021ba1a9cafce6f4943c07d50d821b377d83ffd9 100644 (file)
@@ -160,9 +160,13 @@ cdata_in(PG_FUNCTION_ARGS)
                                ));
 
        while ((*endptr != '\0') && isspace((int)*endptr))
+               ++endptr;
+
+       if (*endptr != '\0')
                ereport(ERROR, (
                                        errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
-                                       errmsg("invalid input syntax for cdata: \"%s\"", orig)
+                                       errmsg("invalid input syntax for cdata: \"%s\"", orig),
+                                       errhint("garbage found after number: \"%s\"", endptr)
                                ));
 
        if (typmod > 0)
@@ -363,6 +367,12 @@ cdata_update(PG_FUNCTION_ARGS)
        data   = PG_GETARG_CDATA_P(0);
        update = PG_GETARG_CDATA_P(1);
 
+       if (! data)
+               PG_RETURN_CDATA_P(update);
+
+       if (! update)
+               PG_RETURN_CDATA_P(data);
+
        if ((data->cf != update->cf) && (update->val_num > 1))
                ereport(ERROR, (
                                        errcode(ERRCODE_INVALID_PARAMETER_VALUE),