Socket
Socket
Sign inDemoInstall

json-ptr

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-ptr - npm Package Compare versions

Comparing version 2.0.1-master.bd99031 to 2.1.0

dist.browser/json-ptr-with-browser-tests.js.LICENSE.txt

18

dist.browser/json-ptr.js

@@ -1,16 +0,2 @@

!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t,n){"use strict";function r(e,t,n){let r="",o=e,i=0,u=-1;for(;(u=o.indexOf(t))>-1;)r+=e.substring(i,i+u)+n,o=o.substring(u+t.length,o.length),i+=u+t.length;return o.length>0&&(r+=e.substring(e.length-o.length,e.length)),r}function o(e){let t=-1;const n=e.length,o=new Array(n);for(;++t<n;)"string"==typeof e[t]?o[t]=r(r(decodeURIComponent(e[t]),"~1","/"),"~0","~"):o[t]=e[t];return o}function i(e){let t=-1;const n=e.length,o=new Array(n);for(;++t<n;)"string"==typeof e[t]?o[t]=encodeURIComponent(r(r(e[t],"~","~0"),"/","~1")):o[t]=e[t];return o}function u(e){let t=-1;const n=e.length,o=new Array(n);for(;++t<n;)"string"==typeof e[t]?o[t]=r(r(e[t],"~1","/"),"~0","~"):o[t]=e[t];return o}function c(e){let t=-1;const n=e.length,o=new Array(n);for(;++t<n;)"string"==typeof e[t]?o[t]=r(r(e[t],"~","~0"),"/","~1"):o[t]=e[t];return o}function a(e){if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length)return[];if("/"!==e[0])throw new ReferenceError("Invalid JSON Pointer syntax. Non-empty pointer must begin with a solidus `/`.");return u(e.substring(1).split("/"))}function f(e){if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length||"#"!==e[0])throw new ReferenceError("Invalid JSON Pointer syntax; URI fragment identifiers must begin with a hash.");if(1===e.length)return[];if("/"!==e[1])throw new ReferenceError("Invalid JSON Pointer syntax.");return o(e.substring(2).split("/"))}function s(e,t){if("number"==typeof t)return t;const n=t.length;if(!n)return-1;let r=0;if(1===n&&"-"===t[0])return Array.isArray(e)?e.length:0;for(;++r<n;)if(t[r]<"0"||t[r]>"9")return-1;return parseInt(t,10)}function l(e){return(null==e?void 0:e.length)>0&&"#"===e[0]}function d(e){return l(e)?f:a}Object.defineProperty(t,"__esModule",{value:!0}),t.decodePtrInit=t.pickDecoder=t.looksLikeFragment=t.unsetValueAtPath=t.setValueAtPath=t.compilePointerDereference=t.toArrayIndexReference=t.encodeUriFragmentIdentifier=t.decodeUriFragmentIdentifier=t.encodePointer=t.decodePointer=t.encodePointerSegments=t.decodePointerSegments=t.encodeFragmentSegments=t.decodeFragmentSegments=t.replace=void 0,t.replace=r,t.decodeFragmentSegments=o,t.encodeFragmentSegments=i,t.decodePointerSegments=u,t.encodePointerSegments=c,t.decodePointer=a,t.encodePointer=function(e){if(!e||e&&!Array.isArray(e))throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"":"/".concat(c(e).join("/"))},t.decodeUriFragmentIdentifier=f,t.encodeUriFragmentIdentifier=function(e){if(!e||e&&!Array.isArray(e))throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"#":"#/".concat(i(e).join("/"))},t.toArrayIndexReference=s,t.compilePointerDereference=function(e){let t="if (typeof(it) !== 'undefined'";return 0===e.length?e=>e:(t=e.reduce((t,n,o)=>t+" && \n\ttypeof((it = it['"+r(e[o]+"","\\","\\\\")+"'])) !== 'undefined'","if (typeof(it) !== 'undefined'"),t+=") {\n\treturn it;\n }",new Function("it",t))},t.setValueAtPath=function(e,t,n,r=!1){if(0===n.length)throw new Error("Cannot set the root object; assign it directly.");if(void 0===e)throw new TypeError("Cannot set values on undefined");let o=e;const i=n.length,u=n.length-1;let c,a,f,l=-1;for(;++l<i;){if(c=n[l],"__proto__"===c||"constructor"===c||"prototype"===c)throw new Error("Attempted prototype pollution disallowed.");if(Array.isArray(o)){if("-"===c&&l===u)return void o.push(t);if(f=s(o,c),o.length>f){if(l===u){a=o[f],o[f]=t;break}o=o[f]}else if(l===u&&f===o.length){if(r)return void o.push(t)}else r&&(o=o[f]=l===u?t:{})}else{if(void 0===o[c]){if(r){if(l===u)return void(o[c]=t);if(-1!==s(o[c],n[l+1])){o=o[c]=[];continue}o=o[c]={};continue}return}if(l===u){a=o[c],o[c]=t;break}o=o[c]}}return a},t.unsetValueAtPath=function(e,t){if(0===t.length)throw new Error("Cannot unset the root object; assign it directly.");if(void 0===e)throw new TypeError("Cannot unset values on undefined");let n=e;const r=t.length,o=t.length-1;let i,u,c,a=-1;for(;++a<r;)if(i=t[a],Array.isArray(n)){if(c=s(n,i),c>=n.length)return;if(a===o){u=n[c],delete n[c];break}n=n[c]}else{if(void 0===n[i])return;if(a===o){u=n[i],delete n[i];break}n=n[i]}return u},t.looksLikeFragment=l,t.pickDecoder=d,t.decodePtrInit=function(e){return Array.isArray(e)?e.slice(0):d(e)(e)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=n(2);r.__exportStar(n(3),t),r.__exportStar(n(0),t),r.__exportStar(n(4),t)},function(e,t,n){"use strict";n.r(t),n.d(t,"__extends",(function(){return o})),n.d(t,"__assign",(function(){return i})),n.d(t,"__rest",(function(){return u})),n.d(t,"__decorate",(function(){return c})),n.d(t,"__param",(function(){return a})),n.d(t,"__metadata",(function(){return f})),n.d(t,"__awaiter",(function(){return s})),n.d(t,"__generator",(function(){return l})),n.d(t,"__createBinding",(function(){return d})),n.d(t,"__exportStar",(function(){return p})),n.d(t,"__values",(function(){return y})),n.d(t,"__read",(function(){return h})),n.d(t,"__spread",(function(){return g})),n.d(t,"__spreadArrays",(function(){return b})),n.d(t,"__await",(function(){return v})),n.d(t,"__asyncGenerator",(function(){return m})),n.d(t,"__asyncDelegator",(function(){return w})),n.d(t,"__asyncValues",(function(){return _})),n.d(t,"__makeTemplateObject",(function(){return P})),n.d(t,"__importStar",(function(){return S})),n.d(t,"__importDefault",(function(){return j})),n.d(t,"__classPrivateFieldGet",(function(){return I})),n.d(t,"__classPrivateFieldSet",(function(){return A}));
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};function o(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var i=function(){return(i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function u(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function c(e,t,n,r){var o,i=arguments.length,u=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(e,t,n,r);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(u=(i<3?o(u):i>3?o(t,n,u):o(t,n))||u);return i>3&&u&&Object.defineProperty(t,n,u),u}function a(e,t){return function(n,r){t(n,r,e)}}function f(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function s(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,c)}a((r=r.apply(e,t||[])).next())}))}function l(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=t.call(e,u)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}var d=Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]};function p(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||d(t,e,n)}function y(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function h(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),u=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return u}function g(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(h(arguments[t]));return e}function b(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var i=arguments[t],u=0,c=i.length;u<c;u++,o++)r[o]=i[u];return r}function v(e){return this instanceof v?(this.v=e,this):new v(e)}function m(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,o=n.apply(e,t||[]),i=[];return r={},u("next"),u("throw"),u("return"),r[Symbol.asyncIterator]=function(){return this},r;function u(e){o[e]&&(r[e]=function(t){return new Promise((function(n,r){i.push([e,t,n,r])>1||c(e,t)}))})}function c(e,t){try{(n=o[e](t)).value instanceof v?Promise.resolve(n.value.v).then(a,f):s(i[0][2],n)}catch(e){s(i[0][3],e)}var n}function a(e){c("next",e)}function f(e){c("throw",e)}function s(e,t){e(t),i.shift(),i.length&&c(i[0][0],i[0][1])}}function w(e){var t,n;return t={},r("next"),r("throw",(function(e){throw e})),r("return"),t[Symbol.iterator]=function(){return this},t;function r(r,o){t[r]=e[r]?function(t){return(n=!n)?{value:v(e[r](t)),done:"return"===r}:o?o(t):t}:o}}function _(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e=y(e),t={},r("next"),r("throw"),r("return"),t[Symbol.asyncIterator]=function(){return this},t);function r(n){t[n]=e[n]&&function(t){return new Promise((function(r,o){(function(e,t,n,r){Promise.resolve(r).then((function(t){e({value:t,done:n})}),t)})(r,o,(t=e[n](t)).done,t.value)}))}}}function P(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}var O=Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t};function S(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&d(t,e,n);return O(t,e),t}function j(e){return e&&e.__esModule?e:{default:e}}function I(e,t){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return t.get(e)}function A(e,t,n){if(!t.has(e))throw new TypeError("attempted to set private field on non-instance");return t.set(e,n),n}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0})},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.JsonReference=t.JsonPointer=void 0;const r=n(0);function o(e){return"object"==typeof e&&null!==e}function i(e){return o(e)&&!d.isReference(e)}function u(e,t,n){const u=new Map,c=[{obj:e,path:[]}];for(;c.length;){const{obj:e,path:a}=c.shift();if(t(n(a),e),i(e))if(u.set(e,new s(r.encodeUriFragmentIdentifier(a))),Array.isArray(e)){let t=-1;const n=e.length;for(;++t<n;){const n=e[t];o(n)&&u.has(n)?c.push({obj:new d(u.get(n)),path:a.concat([t+""])}):c.push({obj:n,path:a.concat([t+""])})}}else{const t=Object.keys(e),n=t.length;let r=-1;for(;++r<n;){const n=e[t[r]];o(n)&&u.has(n)?c.push({obj:new d(u.get(n)),path:a.concat(t[r])}):c.push({obj:n,path:a.concat(t[r])})}}}}const c=Symbol("pointer"),a=Symbol("fragmentId"),f=Symbol("getter");class s{constructor(e){this.path=r.decodePtrInit(e)}static create(e){return new s(e)}static has(e,t){return("string"==typeof t||Array.isArray(t))&&(t=new s(t)),t.has(e)}static get(e,t){return("string"==typeof t||Array.isArray(t))&&(t=new s(t)),t.get(e)}static set(e,t,n,r=!1){return("string"==typeof t||Array.isArray(t))&&(t=new s(t)),t.set(e,n,r)}static unset(e,t){return("string"==typeof t||Array.isArray(t))&&(t=new s(t)),t.unset(e)}static decode(e){return r.pickDecoder(e)(e)}static visit(e,t,n=!1){u(e,t,n?r.encodeUriFragmentIdentifier:r.encodePointer)}static listPointers(e){const t=[];return u(e,(e,n)=>{t.push({pointer:e,value:n})},r.encodePointer),t}static listFragmentIds(e){const t=[];return u(e,(e,n)=>{t.push({fragmentId:e,value:n})},r.encodeUriFragmentIdentifier),t}static flatten(e,t=!1){const n={};return u(e,(e,t)=>{n[e]=t},t?r.encodeUriFragmentIdentifier:r.encodePointer),n}static map(e,t=!1){const n=new Map;return u(e,n.set.bind(n),t?r.encodeUriFragmentIdentifier:r.encodePointer),n}get(e){return this[f]||(this[f]=r.compilePointerDereference(this.path)),this[f](e)}set(e,t,n=!1){return r.setValueAtPath(e,t,this.path,n)}unset(e){return r.unsetValueAtPath(e,this.path)}has(e){return void 0!==this.get(e)}concat(e){return new s(this.path.concat(e instanceof s?e.path:r.decodePtrInit(e)))}get pointer(){return void 0===this[c]&&(this[c]=r.encodePointer(this.path)),this[c]}get uriFragmentIdentifier(){return this[a]||(this[a]=r.encodeUriFragmentIdentifier(this.path)),this[a]}toString(){return this.pointer}}t.JsonPointer=s;const l=Symbol("pointer");class d{constructor(e){this[l]=e instanceof s?e:new s(e),this.$ref=this[l].uriFragmentIdentifier}static isReference(e){if(!e)return!1;const t=e;return"string"==typeof t.$ref&&"function"==typeof t.resolve}resolve(e){return this[l].get(e)}pointer(){return this[l]}toString(){return this.$ref}}t.JsonReference=d}]);
/*! For license information please see json-ptr.js.LICENSE.txt */
(()=>{"use strict";var e={607:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});const n=r(655);n.__exportStar(r(699),t),n.__exportStar(r(882),t),n.__exportStar(r(762),t)},762:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.JsonReference=t.JsonPointer=void 0;const n=r(882);function o(e){return"object"==typeof e&&null!==e}function i(e){return o(e)&&!d.isReference(e)}function a(e,t,r){const a=new Map,c=[{obj:e,path:[]}];for(;c.length;){const{obj:e,path:u}=c.shift();if(t(r(u),e),i(e))if(a.set(e,new f(n.encodeUriFragmentIdentifier(u))),Array.isArray(e)){let t=-1;const r=e.length;for(;++t<r;){const r=e[t];o(r)&&a.has(r)?c.push({obj:new d(a.get(r)),path:u.concat([t+""])}):c.push({obj:r,path:u.concat([t+""])})}}else{const t=Object.keys(e),r=t.length;let n=-1;for(;++n<r;){const r=e[t[n]];o(r)&&a.has(r)?c.push({obj:new d(a.get(r)),path:u.concat(t[n])}):c.push({obj:r,path:u.concat(t[n])})}}}}const c=Symbol("pointer"),u=Symbol("fragmentId"),s=Symbol("getter");class f{constructor(e){this.path=n.decodePtrInit(e)}static create(e){return new f(e)}static has(e,t){return("string"==typeof t||Array.isArray(t))&&(t=new f(t)),t.has(e)}static get(e,t){return("string"==typeof t||Array.isArray(t))&&(t=new f(t)),t.get(e)}static set(e,t,r,n=!1){return("string"==typeof t||Array.isArray(t))&&(t=new f(t)),t.set(e,r,n)}static unset(e,t){return("string"==typeof t||Array.isArray(t))&&(t=new f(t)),t.unset(e)}static decode(e){return n.pickDecoder(e)(e)}static visit(e,t,r=!1){a(e,t,r?n.encodeUriFragmentIdentifier:n.encodePointer)}static listPointers(e){const t=[];return a(e,((e,r)=>{t.push({pointer:e,value:r})}),n.encodePointer),t}static listFragmentIds(e){const t=[];return a(e,((e,r)=>{t.push({fragmentId:e,value:r})}),n.encodeUriFragmentIdentifier),t}static flatten(e,t=!1){const r={};return a(e,((e,t)=>{r[e]=t}),t?n.encodeUriFragmentIdentifier:n.encodePointer),r}static map(e,t=!1){const r=new Map;return a(e,r.set.bind(r),t?n.encodeUriFragmentIdentifier:n.encodePointer),r}get(e){return this[s]||(this[s]=n.compilePointerDereference(this.path)),this[s](e)}set(e,t,r=!1){return n.setValueAtPath(e,t,this.path,r)}unset(e){return n.unsetValueAtPath(e,this.path)}has(e){return void 0!==this.get(e)}concat(e){return new f(this.path.concat(e instanceof f?e.path:n.decodePtrInit(e)))}get pointer(){return void 0===this[c]&&(this[c]=n.encodePointer(this.path)),this[c]}get uriFragmentIdentifier(){return this[u]||(this[u]=n.encodeUriFragmentIdentifier(this.path)),this[u]}toString(){return this.pointer}}t.JsonPointer=f;const l=Symbol("pointer");class d{constructor(e){this[l]=e instanceof f?e:new f(e),this.$ref=this[l].uriFragmentIdentifier}static isReference(e){if(!e)return!1;const t=e;return"string"==typeof t.$ref&&"function"==typeof t.resolve}resolve(e){return this[l].get(e)}pointer(){return this[l]}toString(){return this.$ref}}t.JsonReference=d},699:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},882:(e,t)=>{function r(e,t,r){let n="",o=e,i=0,a=-1;for(;(a=o.indexOf(t))>-1;)n+=e.substring(i,i+a)+r,o=o.substring(a+t.length,o.length),i+=a+t.length;return o.length>0&&(n+=e.substring(e.length-o.length,e.length)),n}function n(e){let t=-1;const n=e.length,o=new Array(n);for(;++t<n;)"string"==typeof e[t]?o[t]=r(r(decodeURIComponent(e[t]),"~1","/"),"~0","~"):o[t]=e[t];return o}function o(e){let t=-1;const n=e.length,o=new Array(n);for(;++t<n;)"string"==typeof e[t]?o[t]=encodeURIComponent(r(r(e[t],"~","~0"),"/","~1")):o[t]=e[t];return o}function i(e){let t=-1;const n=e.length,o=new Array(n);for(;++t<n;)"string"==typeof e[t]?o[t]=r(r(e[t],"~1","/"),"~0","~"):o[t]=e[t];return o}function a(e){let t=-1;const n=e.length,o=new Array(n);for(;++t<n;)"string"==typeof e[t]?o[t]=r(r(e[t],"~","~0"),"/","~1"):o[t]=e[t];return o}function c(e){if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length)return[];if("/"!==e[0])throw new ReferenceError("Invalid JSON Pointer syntax. Non-empty pointer must begin with a solidus `/`.");return i(e.substring(1).split("/"))}function u(e){if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length||"#"!==e[0])throw new ReferenceError("Invalid JSON Pointer syntax; URI fragment identifiers must begin with a hash.");if(1===e.length)return[];if("/"!==e[1])throw new ReferenceError("Invalid JSON Pointer syntax.");return n(e.substring(2).split("/"))}function s(e,t){if("number"==typeof t)return t;const r=t.length;if(!r)return-1;let n=0;if(1===r&&"-"===t[0])return Array.isArray(e)?e.length:0;for(;++n<r;)if(t[n]<"0"||t[n]>"9")return-1;return parseInt(t,10)}function f(e){return(null==e?void 0:e.length)>0&&"#"===e[0]}function l(e){return f(e)?u:c}Object.defineProperty(t,"__esModule",{value:!0}),t.decodePtrInit=t.pickDecoder=t.looksLikeFragment=t.unsetValueAtPath=t.setValueAtPath=t.compilePointerDereference=t.toArrayIndexReference=t.encodeUriFragmentIdentifier=t.decodeUriFragmentIdentifier=t.encodePointer=t.decodePointer=t.encodePointerSegments=t.decodePointerSegments=t.encodeFragmentSegments=t.decodeFragmentSegments=t.replace=void 0,t.replace=r,t.decodeFragmentSegments=n,t.encodeFragmentSegments=o,t.decodePointerSegments=i,t.encodePointerSegments=a,t.decodePointer=c,t.encodePointer=function(e){if(!e||e&&!Array.isArray(e))throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"":"/".concat(a(e).join("/"))},t.decodeUriFragmentIdentifier=u,t.encodeUriFragmentIdentifier=function(e){if(!e||e&&!Array.isArray(e))throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"#":"#/".concat(o(e).join("/"))},t.toArrayIndexReference=s,t.compilePointerDereference=function(e){let t="if (typeof(it) !== 'undefined'";return 0===e.length?e=>e:(t=e.reduce(((t,n,o)=>t+" && \n\ttypeof((it = it['"+r(r(e[o]+"","\\","\\\\"),"'","\\'")+"'])) !== 'undefined'"),"if (typeof(it) !== 'undefined'"),t+=") {\n\treturn it;\n }",new Function("it",t))},t.setValueAtPath=function(e,t,r,n=!1){if(0===r.length)throw new Error("Cannot set the root object; assign it directly.");if(void 0===e)throw new TypeError("Cannot set values on undefined");let o=e;const i=r.length,a=r.length-1;let c,u,f,l=-1;for(;++l<i;){if(c=r[l],"__proto__"===c||"constructor"===c||"prototype"===c)throw new Error("Attempted prototype pollution disallowed.");if(Array.isArray(o)){if("-"===c&&l===a)return void o.push(t);if(f=s(o,c),o.length>f){if(l===a){u=o[f],o[f]=t;break}o=o[f]}else if(l===a&&f===o.length){if(n)return void o.push(t)}else n&&(o=o[f]=l===a?t:{})}else{if(void 0===o[c]){if(n){if(l===a)return void(o[c]=t);if(-1!==s(o[c],r[l+1])){o=o[c]=[];continue}o=o[c]={};continue}return}if(l===a){u=o[c],o[c]=t;break}o=o[c]}}return u},t.unsetValueAtPath=function(e,t){if(0===t.length)throw new Error("Cannot unset the root object; assign it directly.");if(void 0===e)throw new TypeError("Cannot unset values on undefined");let r=e;const n=t.length,o=t.length-1;let i,a,c,u=-1;for(;++u<n;)if(i=t[u],Array.isArray(r)){if(c=s(r,i),c>=r.length)return;if(u===o){a=r[c],delete r[c];break}r=r[c]}else{if(void 0===r[i])return;if(u===o){a=r[i],delete r[i];break}r=r[i]}return a},t.looksLikeFragment=f,t.pickDecoder=l,t.decodePtrInit=function(e){return Array.isArray(e)?e.slice(0):l(e)(e)}},655:(e,t,r)=>{r.r(t),r.d(t,{__extends:()=>o,__assign:()=>i,__rest:()=>a,__decorate:()=>c,__param:()=>u,__metadata:()=>s,__awaiter:()=>f,__generator:()=>l,__createBinding:()=>d,__exportStar:()=>p,__values:()=>h,__read:()=>y,__spread:()=>g,__spreadArrays:()=>b,__spreadArray:()=>w,__await:()=>v,__asyncGenerator:()=>m,__asyncDelegator:()=>_,__asyncValues:()=>P,__makeTemplateObject:()=>O,__importStar:()=>j,__importDefault:()=>I,__classPrivateFieldGet:()=>A,__classPrivateFieldSet:()=>x});var n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)};function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var i=function(){return(i=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function a(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}function c(e,t,r,n){var o,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(a=(i<3?o(a):i>3?o(t,r,a):o(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a}function u(e,t){return function(r,n){t(r,n,e)}}function s(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function f(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function c(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,c)}u((n=n.apply(e,t||[])).next())}))}function l(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}var d=Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]};function p(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||d(t,e,r)}function h(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function y(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a}function g(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(y(arguments[t]));return e}function b(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;var n=Array(e),o=0;for(t=0;t<r;t++)for(var i=arguments[t],a=0,c=i.length;a<c;a++,o++)n[o]=i[a];return n}function w(e,t){for(var r=0,n=t.length,o=e.length;r<n;r++,o++)e[o]=t[r];return e}function v(e){return this instanceof v?(this.v=e,this):new v(e)}function m(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,o=r.apply(e,t||[]),i=[];return n={},a("next"),a("throw"),a("return"),n[Symbol.asyncIterator]=function(){return this},n;function a(e){o[e]&&(n[e]=function(t){return new Promise((function(r,n){i.push([e,t,r,n])>1||c(e,t)}))})}function c(e,t){try{(r=o[e](t)).value instanceof v?Promise.resolve(r.value.v).then(u,s):f(i[0][2],r)}catch(e){f(i[0][3],e)}var r}function u(e){c("next",e)}function s(e){c("throw",e)}function f(e,t){e(t),i.shift(),i.length&&c(i[0][0],i[0][1])}}function _(e){var t,r;return t={},n("next"),n("throw",(function(e){throw e})),n("return"),t[Symbol.iterator]=function(){return this},t;function n(n,o){t[n]=e[n]?function(t){return(r=!r)?{value:v(e[n](t)),done:"return"===n}:o?o(t):t}:o}}function P(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,r=e[Symbol.asyncIterator];return r?r.call(e):(e=h(e),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(r){t[r]=e[r]&&function(t){return new Promise((function(n,o){!function(e,t,r,n){Promise.resolve(n).then((function(t){e({value:t,done:r})}),t)}(n,o,(t=e[r](t)).done,t.value)}))}}}function O(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}var S=Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t};function j(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&d(t,e,r);return S(t,e),t}function I(e){return e&&e.__esModule?e:{default:e}}function A(e,t,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(e):n?n.value:t.get(e)}function x(e,t,r,n,o){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?o.call(e,r):o?o.value=r:t.set(e,r),r}}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r(607)})();

@@ -28,3 +28,3 @@ "use strict";

obj: new JsonReference(distinctObjects.get(it)),
path: path.concat(keys[i])
path: path.concat(keys[i]),
});

@@ -35,3 +35,3 @@ }

obj: it,
path: path.concat(keys[i])
path: path.concat(keys[i]),
});

@@ -49,3 +49,3 @@ }

obj: new JsonReference(distinctObjects.get(it)),
path: path.concat([j + ''])
path: path.concat([j + '']),
});

@@ -56,3 +56,3 @@ }

obj: it,
path: path.concat([j + ''])
path: path.concat([j + '']),
});

@@ -169,3 +169,4 @@ }

constructor(pointer) {
this[$pointer] = pointer instanceof JsonPointer ? pointer : new JsonPointer(pointer);
this[$pointer] =
pointer instanceof JsonPointer ? pointer : new JsonPointer(pointer);
this.$ref = this[$pointer].uriFragmentIdentifier;

@@ -182,3 +183,5 @@ }

}
pointer() { return this[$pointer]; }
pointer() {
return this[$pointer];
}
toString() {

@@ -185,0 +188,0 @@ return this.$ref;

@@ -156,3 +156,6 @@ "use strict";

body = path.reduce((body, _, i) => {
return body + " && \n\ttypeof((it = it['" + replace(path[i] + '', '\\', '\\\\') + "'])) !== 'undefined'";
return (body +
" && \n\ttypeof((it = it['" +
replace(replace(path[i] + '', '\\', '\\\\'), "'", "\\'") +
"'])) !== 'undefined'");
}, "if (typeof(it) !== 'undefined'");

@@ -179,3 +182,5 @@ body = body + ') {\n\treturn it;\n }';

step = path[cursor];
if (step === '__proto__' || step === 'constructor' || step === 'prototype') {
if (step === '__proto__' ||
step === 'constructor' ||
step === 'prototype') {
throw new Error('Attempted prototype pollution disallowed.');

@@ -285,5 +290,7 @@ }

function decodePtrInit(ptr) {
return Array.isArray(ptr) ? ptr.slice(0) : pickDecoder(ptr)(ptr);
return Array.isArray(ptr)
? ptr.slice(0)
: pickDecoder(ptr)(ptr);
}
exports.decodePtrInit = decodePtrInit;
//# sourceMappingURL=util.js.map
{
"name": "json-ptr",
"version": "2.0.1-master.bd99031",
"version": "2.1.0",
"author": "Phillip Clark <phillip@flitbit.com>",

@@ -32,2 +32,3 @@ "description": "A complete implementation of JSON Pointer (RFC 6901) for nodejs and modern browsers.",

"lint": "eslint . --ext .ts,.tsx",
"lint:fix": "eslint . --ext .ts,.tsx --fix",
"pretest": "npm run lint",

@@ -41,30 +42,33 @@ "test": "nyc mocha __tests__/**/*.spec.ts",

"ci": "nyc mocha __tests__/**/*.spec.ts --timeout=10000 --exit --reporter mocha-junit-reporter --reporter-options mochaFile=reports/mocha/test-results.xml",
"docs": "typedoc --theme minimal && cp _config.yml docs/"
"docs": "typedoc --theme minimal --entryPoints src/index.ts && cp _config.yml docs/"
},
"devDependencies": {
"@types/assert-plus": "^1.0.4",
"@types/bent": "^7.3.1",
"@types/chai": "^4.2.14",
"@types/bent": "^7.3.2",
"@types/chai": "^4.2.18",
"@types/debug": "^4.1.5",
"@types/mocha": "^8.0.3",
"@types/node": "~14.14.1",
"@typescript-eslint/eslint-plugin": "~4.5.0",
"@typescript-eslint/parser": "~4.5.0",
"@types/mocha": "^8.2.2",
"@types/node": "~15.0.2",
"@typescript-eslint/eslint-plugin": "^4.23.0",
"@typescript-eslint/parser": "^4.23.0",
"bent": "^7.3.12",
"chai": "^4.2.0",
"chai": "^4.3.4",
"chokidar-cli": "^2.1.0",
"eslint": "^7.11.0",
"eslint-config-prettier": "~6.14.0",
"eslint-plugin-mocha": "^8.0.0",
"mocha": "^8.2.0",
"eslint": "^7.26.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-mocha": "^8.1.0",
"eslint-plugin-prettier": "^3.4.0",
"mocha": "^8.4.0",
"mocha-junit-reporter": "^2.0.0",
"nyc": "^15.1.0",
"prettier": "~2.1.2",
"prettier": "~2.3.0",
"process": "^0.11.10",
"rimraf": "~3.0.2",
"ts-loader": "^8.0.6",
"ts-node": "^9.0.0",
"typedoc": "^0.19.2",
"typescript": "~4.0.3",
"webpack": "^4.44.2",
"webpack-cli": "^4.1.0"
"ts-loader": "^9.1.2",
"ts-node": "^9.1.1",
"typedoc": "^0.20.36",
"typescript": "~4.2.4",
"util": "^0.12.3",
"webpack": "^5.37.0",
"webpack-cli": "^4.7.0"
},

@@ -90,4 +94,4 @@ "nyc": {

"dependencies": {
"tslib": "^2.0.3"
"tslib": "^2.2.0"
}
}

@@ -11,2 +11,8 @@ # json-ptr

## Security Vulnerability prior to v2.1.0
There is a security vulnerability in versions prior to v2.1.0 in which an unscrupulous actor may execute arbitrary code. If your code sends un-sanitized user input to `json-ptr`'s `.get()` method, your project is vulnerable to this injection-style vulnerability.
If your code is vulnerable, you should upgrade immediately, and also, stop sending un-sanitized user input to `json-ptr`.
## Breaking Changes at v1.3.0

@@ -237,2 +243,7 @@

- 2021-05-12 — **2.1.0** _Bug fixes for #28 and #30; **Security Vulnerability Patched**_
- When compiling the accessors for quickly points in an object graph, the `.get()` method was not properly delimiting single quotes. This error caused the get operation to throw an exception in during normal usage. Worse, in cases where malicious user input was sent directly to `json-ptr`, the failure to delimit single quotes allowed the execution of arbitrary code (an injection attack). The first of these issues was reported in #28 by @mprast, the second (vulnerability) by @zpbrent. Thanks also to @elimumford for the actual code used for the fix.
- If your code sent un-sanitized user input to the `.get()` method of `json-ptr`, your project was susceptible to this security vulnerability!
- 2020-10-21 — **2.0.0** _*Breaking Change*_

@@ -239,0 +250,0 @@ - Prototype pollution using this library is now disallowed and will throw an error. I've been looking into the origin of this issue and it seems to have been disclosed by mohan on [huntr.dev](https://www.huntr.dev/bounties/1-npm-json-ptr/). I received [a PR from](https://github.com/flitbit/json-ptr/pull/26) [@luci-m-666](https://github.com/luci-m-666), but found [another PR](https://github.com/418sec/json-ptr/pull/1) by [@alromh87](https://github.com/alromh87) that looks like the origin of the solution. Don't know who to thank, but thanks all -- somebody is due a bounty.

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc