Skip to content

Commit

Permalink
Fix WFS property format writer for multiline strings
Browse files Browse the repository at this point in the history
  When updating a feature through WFS, if there are any newline
  characters in a string properties, these are lost (for example,
  geoserver handles these newlines as whitespace).

  To fix this, multiline string properties should be encoded as
  CDATA block.
  • Loading branch information
aboulan committed Mar 15, 2024
1 parent d5e7d5d commit 3c13544
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/ol/format/WFS.js
Expand Up @@ -25,6 +25,7 @@ import {get as getProjection} from '../proj.js';
import {
readNonNegativeIntegerString,
readPositiveInteger,
writeCDATASection,
writeStringTextNode,
} from './xsd.js';

Expand Down Expand Up @@ -938,7 +939,17 @@ function writeProperty(node, pair, objectStack) {
GML32.prototype.writeGeometryElement(value, pair.value, objectStack);
}
} else {
writeStringTextNode(value, pair.value);
if (typeof pair.value === 'string') {
try {
// Generate a CDATA section to preserve whitespaces.
writeCDATASection(value, pair.value);
} catch {
// If value contains the CDATA closing marker ']]>', fallback to a text node.
writeStringTextNode(value, pair.value);
}
} else {
writeStringTextNode(value, pair.value);
}
}
}
}
Expand Down

0 comments on commit 3c13544

Please sign in to comment.