Skip to content

Commit 075d5b9

Browse files
authored
fix: don't ascii-ise strings (#110)
1 parent 8a12ba9 commit 075d5b9

File tree

7 files changed

+118
-32
lines changed

7 files changed

+118
-32
lines changed

package-lock.json

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"@vitest/coverage-v8": "3.0.8",
4646
"ajv": "8.17.1",
4747
"ajv-formats": "3.0.1",
48-
"any-ascii": "0.3.2",
4948
"eslint": "9.22.0",
5049
"eslint-config-prettier": "10.1.1",
5150
"find-my-way": "9.2.0",

src/__tests__/fixtures/request-parameters-query/opc-results.json

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,53 @@
1616
},
1717
"type": "error"
1818
},
19+
{
20+
"code": "request.query.unknown",
21+
"message": "Query parameter is not defined in the spec file: unicode",
22+
"mockDetails": {
23+
"interactionDescription": "should handle queries with unicode characters",
24+
"interactionState": "[none]",
25+
"location": "[root].interactions[5].request.query.unicode",
26+
"value": "푟Ꝫ띡ⴵ"
27+
},
28+
"specDetails": {
29+
"location": "[root].paths./string.get",
30+
"pathMethod": "get",
31+
"pathName": "/string",
32+
"value": {
33+
"parameters": [
34+
{
35+
"in": "query",
36+
"name": "name",
37+
"required": true,
38+
"schema": {
39+
"type": "string"
40+
}
41+
},
42+
{
43+
"in": "query",
44+
"name": "age",
45+
"schema": {
46+
"type": "number"
47+
}
48+
}
49+
],
50+
"responses": {
51+
"200": {
52+
"description": "OK"
53+
}
54+
}
55+
}
56+
},
57+
"type": "warning"
58+
},
1959
{
2060
"code": "request.query.incompatible",
2161
"message": "Value is incompatible with the parameter defined in the spec file: must be string",
2262
"mockDetails": {
2363
"interactionDescription": "should error when missing parameter using common parameters",
2464
"interactionState": "[none]",
25-
"location": "[root].interactions[7].request.query.local"
65+
"location": "[root].interactions[8].request.query.local"
2666
},
2767
"specDetails": {
2868
"location": "[root].paths./common-parameters.get.parameters[0].schema.type",
@@ -38,7 +78,7 @@
3878
"mockDetails": {
3979
"interactionDescription": "should error when missing parameter using common parameters",
4080
"interactionState": "[none]",
41-
"location": "[root].interactions[7].request.query.common"
81+
"location": "[root].interactions[8].request.query.common"
4282
},
4383
"specDetails": {
4484
"location": "[root].paths./common-parameters.get.parameters[1].schema.type",
@@ -54,7 +94,7 @@
5494
"mockDetails": {
5595
"interactionDescription": "should error when using common parameters that has been overridden",
5696
"interactionState": "[none]",
57-
"location": "[root].interactions[8].request.query.common",
97+
"location": "[root].interactions[9].request.query.common",
5898
"value": "string"
5999
},
60100
"specDetails": {
@@ -71,7 +111,7 @@
71111
"mockDetails": {
72112
"interactionDescription": "should error when exploded query parameter in object form does not match spec",
73113
"interactionState": "[none]",
74-
"location": "[root].interactions[9].request.query.id.2",
114+
"location": "[root].interactions[10].request.query.id.2",
75115
"value": "abc"
76116
},
77117
"specDetails": {
@@ -88,7 +128,7 @@
88128
"mockDetails": {
89129
"interactionDescription": "should error when exploded query parameter in string form does not match spec",
90130
"interactionState": "[none]",
91-
"location": "[root].interactions[10].request.query.id.2",
131+
"location": "[root].interactions[11].request.query.id.2",
92132
"value": "abc"
93133
},
94134
"specDetails": {
@@ -105,7 +145,7 @@
105145
"mockDetails": {
106146
"interactionDescription": "should error when non-exploded query parameter in object form does not match spec",
107147
"interactionState": "[none]",
108-
"location": "[root].interactions[11].request.query.id.2",
148+
"location": "[root].interactions[12].request.query.id.2",
109149
"value": "abc"
110150
},
111151
"specDetails": {
@@ -122,7 +162,7 @@
122162
"mockDetails": {
123163
"interactionDescription": "should error when non-exploded query parameter in string form does not match spec",
124164
"interactionState": "[none]",
125-
"location": "[root].interactions[12].request.query.id.2",
165+
"location": "[root].interactions[13].request.query.id.2",
126166
"value": "abc"
127167
},
128168
"specDetails": {
@@ -139,7 +179,7 @@
139179
"mockDetails": {
140180
"interactionDescription": "should warn about unknown query parameters",
141181
"interactionState": "[none]",
142-
"location": "[root].interactions[13].request.query.unknown_key",
182+
"location": "[root].interactions[14].request.query.unknown_key",
143183
"value": "unknown_value"
144184
},
145185
"specDetails": {
@@ -179,7 +219,7 @@
179219
"mockDetails": {
180220
"interactionDescription": "should error when optional query parameter is incompatible",
181221
"interactionState": "[none]",
182-
"location": "[root].interactions[14].request.query.age",
222+
"location": "[root].interactions[15].request.query.age",
183223
"value": "abc"
184224
},
185225
"specDetails": {
@@ -196,7 +236,7 @@
196236
"mockDetails": {
197237
"interactionDescription": "should error when missing required query parameter",
198238
"interactionState": "[none]",
199-
"location": "[root].interactions[15].request.query.name"
239+
"location": "[root].interactions[16].request.query.name"
200240
},
201241
"specDetails": {
202242
"location": "[root].paths./string.get.parameters[0].schema.type",
@@ -212,7 +252,7 @@
212252
"mockDetails": {
213253
"interactionDescription": "should parse arrays, but not with strings",
214254
"interactionState": "[none]",
215-
"location": "[root].interactions[16].request.query.string",
255+
"location": "[root].interactions[17].request.query.string",
216256
"value": "first,second"
217257
},
218258
"specDetails": {

src/__tests__/fixtures/request-parameters-query/pact.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"consumer": { "name": "consumer" },
33
"provider": { "name": "provider" },
4+
"metadata": {
5+
"pactSpecification": {
6+
"version": "4.0"
7+
}
8+
},
49
"interactions": [
510
{
611
"description": "should pass for query in object form",
@@ -67,6 +72,20 @@
6772
"status": 200
6873
}
6974
},
75+
{
76+
"description": "should handle queries with unicode characters",
77+
"request": {
78+
"method": "GET",
79+
"path": "/string",
80+
"query": {
81+
"unicode": ["푟Ꝫ띡ⴵ"],
82+
"name": ["mark"]
83+
}
84+
},
85+
"response": {
86+
"status": 200
87+
}
88+
},
7089
{
7190
"description": "should pass when using common parameters",
7291
"request": {

src/__tests__/fixtures/request-parameters-query/smv-results.json

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,13 +1051,53 @@
10511051
},
10521052
"type": "error"
10531053
},
1054+
{
1055+
"code": "request.query.unknown",
1056+
"message": "Query parameter is not defined in the spec file: unicode",
1057+
"mockDetails": {
1058+
"interactionDescription": "should handle queries with unicode characters",
1059+
"interactionState": "[none]",
1060+
"location": "[root].interactions[5].request.query.unicode",
1061+
"value": "푟Ꝫ띡ⴵ"
1062+
},
1063+
"specDetails": {
1064+
"location": "[root].paths./string.get",
1065+
"pathMethod": "get",
1066+
"pathName": "/string",
1067+
"value": {
1068+
"parameters": [
1069+
{
1070+
"in": "query",
1071+
"name": "name",
1072+
"required": true,
1073+
"schema": {
1074+
"type": "string"
1075+
}
1076+
},
1077+
{
1078+
"in": "query",
1079+
"name": "age",
1080+
"schema": {
1081+
"type": "number"
1082+
}
1083+
}
1084+
],
1085+
"responses": {
1086+
"200": {
1087+
"description": "OK"
1088+
}
1089+
}
1090+
}
1091+
},
1092+
"type": "warning"
1093+
},
10541094
{
10551095
"code": "request.query.incompatible",
10561096
"message": "Value is incompatible with the parameter defined in the spec file: must have required property 'value'",
10571097
"mockDetails": {
10581098
"interactionDescription": "should error when missing parameter using common parameters",
10591099
"interactionState": "[none]",
1060-
"location": "[root].interactions[7]",
1100+
"location": "[root].interactions[8]",
10611101
"value": {
10621102
"description": "should error when missing parameter using common parameters",
10631103
"request": {
@@ -1090,7 +1130,7 @@
10901130
"mockDetails": {
10911131
"interactionDescription": "should error when missing parameter using common parameters",
10921132
"interactionState": "[none]",
1093-
"location": "[root].interactions[7]",
1133+
"location": "[root].interactions[8]",
10941134
"value": {
10951135
"description": "should error when missing parameter using common parameters",
10961136
"request": {
@@ -1123,7 +1163,7 @@
11231163
"mockDetails": {
11241164
"interactionDescription": "should error when using common parameters that has been overridden",
11251165
"interactionState": "[none]",
1126-
"location": "[root].interactions[8].request.query.common",
1166+
"location": "[root].interactions[9].request.query.common",
11271167
"value": "string"
11281168
},
11291169
"specDetails": {
@@ -1147,7 +1187,7 @@
11471187
"mockDetails": {
11481188
"interactionDescription": "should warn about unknown query parameters",
11491189
"interactionState": "[none]",
1150-
"location": "[root].interactions[13].request.query.unknown_key",
1190+
"location": "[root].interactions[14].request.query.unknown_key",
11511191
"value": "unknown_value"
11521192
},
11531193
"specDetails": {
@@ -1187,7 +1227,7 @@
11871227
"mockDetails": {
11881228
"interactionDescription": "should error when optional query parameter is incompatible",
11891229
"interactionState": "[none]",
1190-
"location": "[root].interactions[14].request.query.age",
1230+
"location": "[root].interactions[15].request.query.age",
11911231
"value": "abc"
11921232
},
11931233
"specDetails": {
@@ -1210,7 +1250,7 @@
12101250
"mockDetails": {
12111251
"interactionDescription": "should error when missing required query parameter",
12121252
"interactionState": "[none]",
1213-
"location": "[root].interactions[15]",
1253+
"location": "[root].interactions[16]",
12141254
"value": {
12151255
"description": "should error when missing required query parameter",
12161256
"request": {

src/documents/pact.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Static, Type } from "@sinclair/typebox";
22
import Ajv, { ErrorObject } from "ajv";
3-
import anyAscii from "any-ascii";
43

54
// a full schema can be found at https://github.com/pactflow/pact-schemas
65
// but we don't use that here, because we try to be permissive with input
@@ -92,7 +91,7 @@ const parseAsPactV4Body = (body: unknown) => {
9291
}
9392
};
9493

95-
const cleanString = (s: string) => anyAscii(s).replaceAll(/[\r\n\0]/g, "");
94+
const cleanString = (s: string) => s.replaceAll(/[\r\n\0]/g, "");
9695

9796
const flattenValues = (
9897
values?: null | string | Record<string, string | string[]>,

src/transform/requestSchema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SchemaObject } from "ajv";
22
import { each } from "lodash-es";
3-
import { traverseWithDereferencing as traverse } from "../utils/schema";
3+
import { traverseWithDereferencing as traverse } from "#utils/schema";
44

55
export const transformRequestSchema = (schema: SchemaObject): SchemaObject => {
66
// OpenAPI defines allOf to mean the union of all sub-schemas. JSON-Schema

0 commit comments

Comments
 (0)