@apidevtools/json-schema-ref-parser 11.2.3 → 11.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import $Refs from "./refs.js";
2
2
  import { JSONParserError, InvalidPointerError, MissingPointerError, ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError } from "./util/errors.js";
3
3
  import type { ParserOptions } from "./options.js";
4
4
  import type { Plugin, $RefsCallback, JSONSchema, SchemaCallback, HTTPResolverOptions, FileInfo, ResolverOptions, JSONSchemaObject } from "./types/index.js";
5
- export { JSONSchemaObject, ResolverOptions, ParserError, UnmatchedResolverError, ResolverError, HTTPResolverOptions, FileInfo, UnmatchedParserError, ParserOptions, MissingPointerError, InvalidPointerError, JSONParserError, Plugin, };
5
+ export { JSONSchemaObject, ResolverOptions, ParserError, UnmatchedResolverError, ResolverError, HTTPResolverOptions, FileInfo, UnmatchedParserError, ParserOptions, MissingPointerError, InvalidPointerError, JSONParserError, Plugin, JSONSchema, $RefsCallback, SchemaCallback, };
6
6
  export type RefParserSchema = string | JSONSchema;
7
7
  /**
8
8
  * This class parses a JSON schema, builds a map of its JSON references and their resolved values,
@@ -33,6 +33,14 @@ const slashes = /\//g;
33
33
  const tildes = /~/g;
34
34
  const escapedSlash = /~1/g;
35
35
  const escapedTilde = /~0/g;
36
+ const safeDecodeURIComponent = (encodedURIComponent) => {
37
+ try {
38
+ return decodeURIComponent(encodedURIComponent);
39
+ }
40
+ catch {
41
+ return encodedURIComponent;
42
+ }
43
+ };
36
44
  /**
37
45
  * This class represents a single JSON pointer and its resolved value.
38
46
  *
@@ -153,7 +161,7 @@ class Pointer {
153
161
  pointer = pointer.split("/");
154
162
  // Decode each part, according to RFC 6901
155
163
  for (let i = 0; i < pointer.length; i++) {
156
- pointer[i] = decodeURIComponent(pointer[i].replace(escapedSlash, "/").replace(escapedTilde, "~"));
164
+ pointer[i] = safeDecodeURIComponent(pointer[i].replace(escapedSlash, "/").replace(escapedTilde, "~"));
157
165
  }
158
166
  if (pointer[0] !== "") {
159
167
  throw new errors_js_1.InvalidPointerError(pointer, originalPath === undefined ? path : originalPath);
@@ -215,8 +215,11 @@ function fromFileSystemPath(path) {
215
215
  const posixUpper = projectDirPosixPath.toUpperCase();
216
216
  const hasProjectDir = upperPath.includes(posixUpper);
217
217
  const hasProjectUri = upperPath.includes(posixUpper);
218
- const isAbsolutePath = path_1.win32?.isAbsolute(path);
219
- if (!(hasProjectDir || hasProjectUri || isAbsolutePath)) {
218
+ const isAbsolutePath = path_1.win32?.isAbsolute(path) ||
219
+ path.startsWith("http://") ||
220
+ path.startsWith("https://") ||
221
+ path.startsWith("file://");
222
+ if (!(hasProjectDir || hasProjectUri || isAbsolutePath) && !projectDir.startsWith("http")) {
220
223
  path = (0, path_2.join)(projectDir, path);
221
224
  }
222
225
  path = (0, convert_path_to_posix_1.default)(path);
package/lib/index.ts CHANGED
@@ -44,6 +44,9 @@ export {
44
44
  InvalidPointerError,
45
45
  JSONParserError,
46
46
  Plugin,
47
+ JSONSchema,
48
+ $RefsCallback,
49
+ SchemaCallback,
47
50
  };
48
51
 
49
52
  export type RefParserSchema = string | JSONSchema;
package/lib/pointer.ts CHANGED
@@ -8,6 +8,14 @@ const tildes = /~/g;
8
8
  const escapedSlash = /~1/g;
9
9
  const escapedTilde = /~0/g;
10
10
 
11
+ const safeDecodeURIComponent = (encodedURIComponent: string): string => {
12
+ try {
13
+ return decodeURIComponent(encodedURIComponent);
14
+ } catch {
15
+ return encodedURIComponent;
16
+ }
17
+ };
18
+
11
19
  /**
12
20
  * This class represents a single JSON pointer and its resolved value.
13
21
  *
@@ -181,7 +189,7 @@ class Pointer {
181
189
 
182
190
  // Decode each part, according to RFC 6901
183
191
  for (let i = 0; i < pointer.length; i++) {
184
- pointer[i] = decodeURIComponent(pointer[i].replace(escapedSlash, "/").replace(escapedTilde, "~"));
192
+ pointer[i] = safeDecodeURIComponent(pointer[i].replace(escapedSlash, "/").replace(escapedTilde, "~"));
185
193
  }
186
194
 
187
195
  if (pointer[0] !== "") {
package/lib/util/url.ts CHANGED
@@ -191,9 +191,13 @@ export function fromFileSystemPath(path: string) {
191
191
  const posixUpper = projectDirPosixPath.toUpperCase();
192
192
  const hasProjectDir = upperPath.includes(posixUpper);
193
193
  const hasProjectUri = upperPath.includes(posixUpper);
194
- const isAbsolutePath = win32?.isAbsolute(path);
194
+ const isAbsolutePath =
195
+ win32?.isAbsolute(path) ||
196
+ path.startsWith("http://") ||
197
+ path.startsWith("https://") ||
198
+ path.startsWith("file://");
195
199
 
196
- if (!(hasProjectDir || hasProjectUri || isAbsolutePath)) {
200
+ if (!(hasProjectDir || hasProjectUri || isAbsolutePath) && !projectDir.startsWith("http")) {
197
201
  path = join(projectDir, path);
198
202
  }
199
203
  path = convertPathToPosix(path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apidevtools/json-schema-ref-parser",
3
- "version": "11.2.3",
3
+ "version": "11.2.4",
4
4
  "description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
5
5
  "keywords": [
6
6
  "json",