bare-url 1.0.4 → 1.0.6

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.
package/CMakeLists.txt CHANGED
@@ -16,6 +16,8 @@ add_bare_module(bare_url)
16
16
 
17
17
  target_sources(
18
18
  ${bare_url}
19
+ PUBLIC
20
+ $<TARGET_OBJECTS:url>
19
21
  PRIVATE
20
22
  binding.c
21
23
  )
@@ -23,5 +25,5 @@ target_sources(
23
25
  target_link_libraries(
24
26
  ${bare_url}
25
27
  PUBLIC
26
- url_static
28
+ url
27
29
  )
package/index.js CHANGED
@@ -1,9 +1,11 @@
1
+ /* global Bare */
1
2
  const path = require('bare-path')
2
- const os = require('bare-os')
3
3
  const safetyCatch = require('safety-catch')
4
4
  const binding = require('./binding')
5
5
  const errors = require('./lib/errors')
6
6
 
7
+ const isWindows = Bare.platform === 'win32'
8
+
7
9
  const URL = exports.URL = class URL {
8
10
  constructor (href, base) {
9
11
  if (typeof href !== 'string') throw errors.INVALID_URL()
@@ -195,11 +197,31 @@ exports.fileURLToPath = function fileURLToPath (url) {
195
197
  throw errors.INVALID_URL_SCHEME('The URL must use the file: protocol')
196
198
  }
197
199
 
200
+ if (isWindows) {
201
+ if (/%2f|%5c/i.test(url.pathname)) {
202
+ throw errors.INVALID_FILE_URL_PATH('The file: URL path must not include encoded \\ or / characters')
203
+ }
204
+ } else {
205
+ if (url.hostname) {
206
+ throw errors.INVALID_FILE_URL_HOST('The file: URL host must be \'localhost\' or empty')
207
+ }
208
+
209
+ if (/%2f/i.test(url.pathname)) {
210
+ throw errors.INVALID_FILE_URL_PATH('The file: URL path must not include encoded / characters')
211
+ }
212
+ }
213
+
198
214
  const pathname = path.normalize(decodeURIComponent(url.pathname))
199
215
 
200
- if (os.platform() === 'win32') {
216
+ if (isWindows) {
201
217
  if (url.hostname) return '\\\\' + url.hostname + pathname
202
218
 
219
+ const letter = pathname.charCodeAt(1) | 0x20
220
+
221
+ if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */) {
222
+ throw errors.INVALID_FILE_URL_PATH('The file: URL path must be absolute')
223
+ }
224
+
203
225
  return pathname.slice(1)
204
226
  }
205
227
 
@@ -211,7 +233,7 @@ exports.pathToFileURL = function pathToFileURL (pathname) {
211
233
 
212
234
  if (pathname[pathname.length - 1] === '/') {
213
235
  resolved += '/'
214
- } else if (os.platform() === 'win32' && pathname[pathname.length - 1 === '\\']) {
236
+ } else if (isWindows && pathname[pathname.length - 1 === '\\']) {
215
237
  resolved += '\\'
216
238
  }
217
239
 
@@ -223,7 +245,7 @@ exports.pathToFileURL = function pathToFileURL (pathname) {
223
245
  .replaceAll('\r', '%0d')
224
246
  .replaceAll('\t', '%09')
225
247
 
226
- if (os.platform() !== 'win32') {
248
+ if (!isWindows) {
227
249
  resolved = resolved.replaceAll('\\', '%5c')
228
250
  }
229
251
 
package/lib/errors.js CHANGED
@@ -19,4 +19,12 @@ module.exports = class URLError extends Error {
19
19
  static INVALID_URL_SCHEME (msg = 'Invalid URL') {
20
20
  return new URLError(msg, 'INVALID_URL_SCHEME', URLError.INVALID_URL_SCHEME)
21
21
  }
22
+
23
+ static INVALID_FILE_URL_HOST (msg = 'Invalid file: URL host') {
24
+ return new URLError(msg, 'INVALID_FILE_URL_HOST', URLError.INVALID_FILE_URL_HOST)
25
+ }
26
+
27
+ static INVALID_FILE_URL_PATH (msg = 'Invalid file: URL path') {
28
+ return new URLError(msg, 'INVALID_FILE_URL_PATH', URLError.INVALID_FILE_URL_PATH)
29
+ }
22
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-url",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "URL parser for JavaScript",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -30,7 +30,6 @@
30
30
  },
31
31
  "homepage": "https://github.com/holepunchto/bare-url",
32
32
  "dependencies": {
33
- "bare-os": "^2.0.0",
34
33
  "bare-path": "^2.0.0",
35
34
  "safety-catch": "^1.0.2"
36
35
  },