braidfs 0.0.111 → 0.0.113

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.
Files changed (2) hide show
  1. package/index.js +17 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -71,10 +71,12 @@ if (argv.length === 1 && argv[0].match(/^(run|serve)$/)) {
71
71
  for (let i = 0; i < argv.length; i += 2) {
72
72
  var sync = argv[i] === 'sync',
73
73
  url = argv[i + 1]
74
- if (!url.match(/^https?:\/\//)) {
75
- if (url.startsWith('/')) url = require('path').relative(sync_base, url)
76
- url = `https://${url}`
74
+
75
+ if (!is_well_formed_absolute_url(url)) {
76
+ console.log(`malformed url: ${url}`)
77
+ return
77
78
  }
79
+
78
80
  console.log(`${sync ? '' : 'un'}subscribing ${sync ? 'to' : 'from'} ${url}`)
79
81
  try {
80
82
  var res = await braid_fetch(`http://localhost:${config.port}/.braidfs/config`, {
@@ -299,7 +301,7 @@ async function watch_files() {
299
301
  on('unlink', x => chokidar_handler(x, 'unlink'))
300
302
 
301
303
  async function chokidar_handler(fullpath, event) {
302
- console.log(`file event "${event}": ${fullpath}`)
304
+ // console.log(`file event "${event}": ${fullpath}`)
303
305
 
304
306
  // Make sure the path is within sync_base..
305
307
  if (!fullpath.startsWith(sync_base))
@@ -1387,3 +1389,14 @@ async function file_exists(fullpath) {
1387
1389
  function sha256(x) {
1388
1390
  return require('crypto').createHash('sha256').update(x).digest('base64')
1389
1391
  }
1392
+
1393
+ function is_well_formed_absolute_url(urlString) {
1394
+ if (!urlString || typeof urlString !== 'string') return
1395
+ if (urlString.match(/\s/)) return
1396
+ try {
1397
+ var url = new URL(urlString)
1398
+ if (url.hostname.includes('%')) return
1399
+ if (!url.hostname) return
1400
+ return urlString.match(/^https?:\/\//)
1401
+ } catch (error) {}
1402
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braidfs",
3
- "version": "0.0.111",
3
+ "version": "0.0.113",
4
4
  "description": "braid technology synchronizing files and webpages",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braidfs",