Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## 3.3.1 (2025-11-21)

- [uploadChangeset] fix tag values with linebreaks (`\n`) not handled properly

## 3.3.0 (2025-09-18)

- [uploadChangeset] add an `onProgress` callback, so that apps can show a progress bar while uploading
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "osm-api",
"version": "3.3.0",
"version": "3.3.1",
"contributors": [
"Kyle Hensel (https://github.com/k-yle)"
],
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/_createOsmChangeXml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe("createOsmChangeXml", () => {
type: "way",
id: 4002,
version: 2,
tags: { highway: "path", surface: "< & \" ' >" },
tags: { highway: "path", surface: "< & \" ' > \n \r \t" },
nodes: [3005, 3006, 3007, -3, 3008, 3009, 3010],
},
{
Expand Down Expand Up @@ -107,7 +107,7 @@ describe("createOsmChangeXml", () => {
</way>
<way id="4002" version="2" changeset="6001">
<tag k="highway" v="path"/>
<tag k="surface" v="&lt; &amp; &quot; &apos; &gt;"/>
<tag k="surface" v="&lt; &amp; &quot; &apos; &gt; &#10; &#13; &#9;"/>
<nd ref="3005"/>
<nd ref="3006"/>
<nd ref="3007"/>
Expand Down
6 changes: 6 additions & 0 deletions src/api/_xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ export const xmlParser = new XMLParser({
attributesGroupName: "$",
attributeNamePrefix: "",
isArray: (tagName) => tagName !== "$",
attributeValueProcessor(_name, value) {
return value
.replaceAll(/&#(x9|9);/g, "\t")
.replaceAll(/&#(xA|10);/g, "\n")
.replaceAll(/&#(xD|13);/g, "\r");
},
});
4 changes: 4 additions & 0 deletions src/api/changesets/__tests__/_parseOsmChangeXml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ describe("_parseOsmChangeXml", () => {
<modify>
<way id="-2" version="0" changeset="123">
<tag k="building" v="yes"/>
<tag k="inscription" v="a&#10;b&#13;&#10;c"/>
<tag k="surface" v="&lt; &amp; &quot; &apos; &gt; &#10; &#13; &#9;"/>
<nd ref="10"/>
<nd ref="11"/>
<nd ref="12"/>
Expand Down Expand Up @@ -55,6 +57,8 @@ describe("_parseOsmChangeXml", () => {
nodes: [10, 11, 12, 13, 10],
tags: {
building: "yes",
inscription: "a\nb\r\nc",
surface: "< & \" ' > \n \r \t",
},
timestamp: undefined,
type: "way",
Expand Down
16 changes: 16 additions & 0 deletions src/api/changesets/_createOsmChangeXml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ const builder = new XMLBuilder({
format: true,
suppressEmptyNode: true,
suppressBooleanAttributes: false,
// @ts-expect-error -- typedefs are wrong
entities: [
{ regex: /&/g, val: "&amp;" },
{ regex: />/g, val: "&gt;" },
{ regex: /</g, val: "&lt;" },
{ regex: /'/g, val: "&apos;" },
{ regex: /"/g, val: "&quot;" },
{ regex: /\t/g, val: "&#9;" },
{ regex: /\n/g, val: "&#10;" },
{ regex: /\r/g, val: "&#13;" },
// we need this because the library only defines a subset of
// the characters that need to be escaped. compare:
// https://github.com/NaturalIntelligence/fast-xml-parser/blob/e0769f/src/xmlbuilder/json2xml.js#L27-L31
// with
// https://github.com/jsdom/w3c-xmlserializer/blob/83115f/lib/attributes.js#L30-L36
],
});

/** @internal */
Expand Down