Skip to content

Commit 781d1fe

Browse files
authored
Merge pull request #1896 from joto/fix-utf8-json
Fix for UTF-8 characters in JSON
2 parents 4f045d7 + fd0a2ef commit 781d1fe

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

.github/actions/win-test/action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ runs:
66
steps:
77
- name: Test
88
run: ctest --output-on-failure -C Release
9+
env:
10+
PYTHONUTF8: 1
911
shell: bash
1012
working-directory: build
1113

src/json-writer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class json_writer_t
6969
m_buffer.append("\\\\");
7070
break;
7171
default:
72-
if (c <= 0x1f) {
72+
if (static_cast<unsigned char>(c) <= 0x1fU) {
7373
m_buffer.append(fmt::format(R"(\u{:04x})",
7474
static_cast<unsigned char>(c)));
7575
} else {

tests/bdd/flex/tags.feature

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
Feature: Handling of tags
2+
3+
Scenario: Write tags in different forms to table
4+
Given the OSM data
5+
"""
6+
n10 v1 dV Tname=Paris x10.0 y10.0
7+
n11 v1 dV Tname=Nürnberg x10.0 y10.0
8+
n12 v1 dV Tname=Plzeň x10.0 y10.0
9+
n13 v1 dV Tname=Αθήνα x10.0 y10.0
10+
n14 v1 dV Tname=תל־אביב-יפו x10.0 y10.0
11+
n15 v1 dV Tname=عَمَّان x10.0 y10.0
12+
n16 v1 dV Tname=北京 x10.0 y10.0
13+
n17 v1 dV Tname=ရန်ကုန် x10.0 y10.0
14+
n18 v1 dV Tname=मुंबई x10.0 y10.0
15+
"""
16+
And the lua style
17+
"""
18+
local pois = osm2pgsql.define_node_table('osm2pgsql_test_pois', {
19+
{ column = 'name', type = 'text' },
20+
{ column = 'htags', type = 'hstore' },
21+
{ column = 'jtags', type = 'json' },
22+
{ column = 'btags', type = 'jsonb' },
23+
})
24+
25+
function osm2pgsql.process_node(object)
26+
pois:insert{
27+
name = object.tags.name,
28+
htags = object.tags,
29+
jtags = object.tags,
30+
btags = object.tags
31+
}
32+
end
33+
"""
34+
When running osm2pgsql flex
35+
36+
Then table osm2pgsql_test_pois contains exactly
37+
| node_id | name | htags->'name' | jtags->>'name' | btags->>'name' |
38+
| 10 | Paris | Paris | Paris | Paris |
39+
| 11 | Nürnberg | Nürnberg | Nürnberg | Nürnberg |
40+
| 12 | Plzeň | Plzeň | Plzeň | Plzeň |
41+
| 13 | Αθήνα | Αθήνα | Αθήνα | Αθήνα |
42+
| 14 | תל־אביב-יפו | תל־אביב-יפו | תל־אביב-יפו | תל־אביב-יפו |
43+
| 15 | عَمَّان | عَمَّان | عَمَّان | عَمَّان |
44+
| 16 | 北京 | 北京 | 北京 | 北京 |
45+
| 17 | ရန်ကုန် | ရန်ကုန် | ရန်ကုန် | ရန်ကုန် |
46+
| 18 | मुंबई | मुंबई | मुंबई | मुंबई |
47+
48+
Scenario: Write tags with special characters in different forms to table
49+
Given the OSM data
50+
"""
51+
n10 v1 dV Tname= x10.0 y10.0
52+
n11 v1 dV Tname=<%20%> x10.0 y10.0
53+
n12 v1 dV Tname=<%09%> x10.0 y10.0
54+
n13 v1 dV Tname=<%1B%%0A%> x10.0 y10.0
55+
n14 v1 dV Tname=<%01%%1F%> x10.0 y10.0
56+
"""
57+
And the lua style
58+
"""
59+
local pois = osm2pgsql.define_node_table('osm2pgsql_test_pois', {
60+
{ column = 'name', type = 'text' },
61+
{ column = 'htags', type = 'hstore' },
62+
{ column = 'jtags', type = 'json' },
63+
{ column = 'btags', type = 'jsonb' },
64+
})
65+
66+
function osm2pgsql.process_node(object)
67+
pois:insert{
68+
name = object.tags.name,
69+
htags = object.tags,
70+
jtags = object.tags,
71+
btags = object.tags
72+
}
73+
end
74+
"""
75+
When running osm2pgsql flex
76+
77+
Then table osm2pgsql_test_pois contains exactly
78+
| node_id | encode(name::bytea, 'hex') | encode((htags->'name')::bytea, 'hex') | encode((jtags->>'name')::bytea, 'hex') | encode((btags->>'name')::bytea, 'hex') |
79+
| 10 | | | | |
80+
| 11 | 3c203e | 3c203e | 3c203e | 3c203e |
81+
| 12 | 3c093e | 3c093e | 3c093e | 3c093e |
82+
| 13 | 3c1b0a3e | 3c1b0a3e | 3c1b0a3e | 3c1b0a3e |
83+
| 14 | 3c011f3e | 3c011f3e | 3c011f3e | 3c011f3e |
84+

0 commit comments

Comments
 (0)