*** pgsql/src/backend/utils/adt/xml.c 2009/06/11 14:49:04 1.92 --- pgsql/src/backend/utils/adt/xml.c 2009/08/10 05:46:50 1.93 *************** *** 7,13 **** * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * ! * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.91 2009/06/10 03:44:35 tgl Exp $ * *------------------------------------------------------------------------- */ --- 7,13 ---- * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * ! * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.92 2009/06/11 14:49:04 momjian Exp $ * *------------------------------------------------------------------------- */ *************** map_xml_name_to_sql_identifier(char *nam *** 1593,1600 **** char * map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings) { - StringInfoData buf; - if (type_is_array(type)) { ArrayType *array; --- 1593,1598 ---- *************** map_sql_value_to_xml_value(Datum value, *** 1605,1610 **** --- 1603,1609 ---- int num_elems; Datum *elem_values; bool *elem_nulls; + StringInfoData buf; int i; array = DatumGetArrayTypeP(value); *************** map_sql_value_to_xml_value(Datum value, *** 1638,1645 **** { Oid typeOut; bool isvarlena; ! char *p, ! *str; /* * Special XSD formatting for some data types --- 1637,1643 ---- { Oid typeOut; bool isvarlena; ! char *str; /* * Special XSD formatting for some data types *************** map_sql_value_to_xml_value(Datum value, *** 1788,1819 **** return str; /* otherwise, translate special characters as needed */ ! initStringInfo(&buf); ! for (p = str; *p; p++) { ! switch (*p) ! { ! case '&': ! appendStringInfoString(&buf, "&"); ! break; ! case '<': ! appendStringInfoString(&buf, "<"); ! break; ! case '>': ! appendStringInfoString(&buf, ">"); ! break; ! case '\r': ! appendStringInfoString(&buf, " "); ! break; ! default: ! appendStringInfoCharMacro(&buf, *p); ! break; ! } } - - return buf.data; } } --- 1786,1832 ---- return str; /* otherwise, translate special characters as needed */ ! return escape_xml(str); ! } ! } ! ! /* ! * Escape characters in text that have special meanings in XML. ! * ! * Returns a palloc'd string. ! * ! * NB: this is intentionally not dependent on libxml. ! */ ! char * ! escape_xml(const char *str) ! { ! StringInfoData buf; ! const char *p; ! ! initStringInfo(&buf); ! for (p = str; *p; p++) ! { ! switch (*p) { ! case '&': ! appendStringInfoString(&buf, "&"); ! break; ! case '<': ! appendStringInfoString(&buf, "<"); ! break; ! case '>': ! appendStringInfoString(&buf, ">"); ! break; ! case '\r': ! appendStringInfoString(&buf, " "); ! break; ! default: ! appendStringInfoCharMacro(&buf, *p); ! break; } } + return buf.data; }