jsonrepair
Advanced tools
Comparing version 3.4.0 to 3.4.1
@@ -333,5 +333,13 @@ "use strict"; | ||
} else if (char === 'u') { | ||
if ((0, _stringUtils.isHex)(text.charCodeAt(i + 2)) && (0, _stringUtils.isHex)(text.charCodeAt(i + 3)) && (0, _stringUtils.isHex)(text.charCodeAt(i + 4)) && (0, _stringUtils.isHex)(text.charCodeAt(i + 5))) { | ||
let j = 2; | ||
while (j < 6 && (0, _stringUtils.isHex)(text.charCodeAt(i + j))) { | ||
j++; | ||
} | ||
if (j === 6) { | ||
output += text.slice(i, i + 6); | ||
i += 6; | ||
} else if (j < 6 && i + j >= text.length) { | ||
// repair invalid or truncated unicode char at the end of the text | ||
// by removing the unicode char and ending the string here | ||
i = text.length; | ||
} else { | ||
@@ -563,8 +571,4 @@ throwInvalidUnicodeCharacter(i); | ||
} | ||
function throwInvalidUnicodeCharacter(start) { | ||
let end = start + 2; | ||
while (/\w/.test(text[end])) { | ||
end++; | ||
} | ||
const chars = text.slice(start, end); | ||
function throwInvalidUnicodeCharacter(i) { | ||
const chars = text.slice(i, i + 6); | ||
throw new _JSONRepairError.JSONRepairError(`Invalid unicode character "${chars}"`, i); | ||
@@ -571,0 +575,0 @@ } |
@@ -327,5 +327,13 @@ import { JSONRepairError } from './JSONRepairError.js'; | ||
} else if (char === 'u') { | ||
if (isHex(text.charCodeAt(i + 2)) && isHex(text.charCodeAt(i + 3)) && isHex(text.charCodeAt(i + 4)) && isHex(text.charCodeAt(i + 5))) { | ||
let j = 2; | ||
while (j < 6 && isHex(text.charCodeAt(i + j))) { | ||
j++; | ||
} | ||
if (j === 6) { | ||
output += text.slice(i, i + 6); | ||
i += 6; | ||
} else if (j < 6 && i + j >= text.length) { | ||
// repair invalid or truncated unicode char at the end of the text | ||
// by removing the unicode char and ending the string here | ||
i = text.length; | ||
} else { | ||
@@ -557,8 +565,4 @@ throwInvalidUnicodeCharacter(i); | ||
} | ||
function throwInvalidUnicodeCharacter(start) { | ||
let end = start + 2; | ||
while (/\w/.test(text[end])) { | ||
end++; | ||
} | ||
const chars = text.slice(start, end); | ||
function throwInvalidUnicodeCharacter(i) { | ||
const chars = text.slice(i, i + 6); | ||
throw new JSONRepairError(`Invalid unicode character "${chars}"`, i); | ||
@@ -565,0 +569,0 @@ } |
@@ -500,5 +500,13 @@ (function (global, factory) { | ||
} else if (char === 'u') { | ||
if (isHex(text.charCodeAt(i + 2)) && isHex(text.charCodeAt(i + 3)) && isHex(text.charCodeAt(i + 4)) && isHex(text.charCodeAt(i + 5))) { | ||
let j = 2; | ||
while (j < 6 && isHex(text.charCodeAt(i + j))) { | ||
j++; | ||
} | ||
if (j === 6) { | ||
output += text.slice(i, i + 6); | ||
i += 6; | ||
} else if (j < 6 && i + j >= text.length) { | ||
// repair invalid or truncated unicode char at the end of the text | ||
// by removing the unicode char and ending the string here | ||
i = text.length; | ||
} else { | ||
@@ -727,8 +735,4 @@ throwInvalidUnicodeCharacter(i); | ||
} | ||
function throwInvalidUnicodeCharacter(start) { | ||
let end = start + 2; | ||
while (/\w/.test(text[end])) { | ||
end++; | ||
} | ||
const chars = text.slice(start, end); | ||
function throwInvalidUnicodeCharacter(i) { | ||
const chars = text.slice(i, i + 6); | ||
throw new JSONRepairError(`Invalid unicode character "${chars}"`, i); | ||
@@ -735,0 +739,0 @@ } |
@@ -1,3 +0,3 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).JSONRepair={})}(this,function(t){"use strict";class v extends Error{constructor(t,e){super(t+" at position "+e),this.position=e}}const a=125,e=32,b=10,p=9,w=13,x=8,y=12,$=34,r=39,n=48,o=57,c=65,i=97,f=70,u=102,h=160,O=8192,N=8202,J=8239,S=8287,j=12288,d=8220,l=8221,s=8216,A=8217,C=96,g=180;function I(t){return t>=n&&t<=o||t>=c&&t<=f||t>=i&&t<=u}function k(t){return t>=n&&t<=o}function m(t){return G.test(t)||t&&R(t.charCodeAt(0))}const G=/^[,:[\]{}()\n+]$/;function T(t){return H.test(t)||t&&R(t.charCodeAt(0))}const H=/^[[{\w-]$/;function E(t){return t===e||t===b||t===p||t===w}function R(t){return U(t)||q(t)}function U(t){return t===$||t===d||t===l}function F(t){return t===$}function q(t){return t===r||t===s||t===A||t===C||t===g}function z(t){return t===r}function B(t,e,r){r=2<arguments.length&&void 0!==r&&r,e=t.lastIndexOf(e);return-1!==e?t.substring(0,e)+(r?"":t.substring(e+1)):t}function D(t,e){let r=t.length;if(!E(t.charCodeAt(r-1)))return t+e;for(;E(t.charCodeAt(r-1));)r--;return t.substring(0,r)+e+t.substring(r)}const K={"\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t"},L={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};t.JSONRepairError=v,t.jsonrepair=function(d){let l=0,s="";if(!c())throw new v("Unexpected end of json string",d.length);var t=i(44);if(t&&A(),T(d[l])&&/[,\n][ \t\r]*$/.test(s)){t||(s=D(s,","));{let t=!0,e=!0;for(;e;)t?t=!1:i(44)||(s=D(s,",")),e=c();e||(s=B(s,","));s=`[ | ||
${s} | ||
]`}}else t&&(s=B(s,","));for(;d.charCodeAt(l)===a||93===d.charCodeAt(l);)l++,A();if(l>=d.length)return s;throw new v("Unexpected character "+JSON.stringify(d[l]),l);function c(){A();var t=function(){if(123!==d.charCodeAt(l))return!1;{s+="{",l++,A();let e=!0;for(;l<d.length&&d.charCodeAt(l)!==a;){let t;if(e?(t=!0,e=!1):((t=i(44))||(s=D(s,",")),A()),!(g()||f())){d.charCodeAt(l)===a||123===d.charCodeAt(l)||93===d.charCodeAt(l)||91===d.charCodeAt(l)||void 0===d[l]?s=B(s,","):function(){throw new v("Object key expected",l)}();break}A();var r=i(58),n=l>=d.length,o=(r||(T(d[l])||n?s=D(s,":"):u()),c());o||(r||n?s+="null":u())}return d.charCodeAt(l)===a?(s+="}",l++):s=D(s,"}"),!0}}()||function(){if(91!==d.charCodeAt(l))return!1;{s+="[",l++,A();let t=!0;for(;l<d.length&&93!==d.charCodeAt(l);){t?t=!1:i(44)||(s=D(s,","));var e=c();if(!e){s=B(s,",");break}}return 93===d.charCodeAt(l)?(s+="]",l++):s=D(s,"]"),!0}}()||g()||function(){var t=l;if(45===d.charCodeAt(l)&&(l++,o(t)))return!0;for(;k(d.charCodeAt(l));)l++;if(46===d.charCodeAt(l)){if(l++,o(t))return!0;for(;k(d.charCodeAt(l));)l++}if(101===d.charCodeAt(l)||69===d.charCodeAt(l)){if(l++,45!==d.charCodeAt(l)&&43!==d.charCodeAt(l)||l++,o(t))return!0;for(;k(d.charCodeAt(l));)l++}{var e;if(l>t)return t=d.slice(t,l),e=/^0\d/.test(t),s+=e?`"${t}"`:t,!0}return!1}()||r("true","true")||r("false","false")||r("null","null")||r("True","true")||r("False","false")||r("None","null")||f();return A(),t}function A(){l;let t=e();for(;t=(t=function(){if(47===d.charCodeAt(l)&&42===d.charCodeAt(l+1)){for(;l<d.length&&!function(t,e){return"*"===t[e]&&"/"===t[e+1]}(d,l);)l++;l+=2}else{if(47!==d.charCodeAt(l)||47!==d.charCodeAt(l+1))return!1;for(;l<d.length&&d.charCodeAt(l)!==b;)l++}return!0}())&&e(););l}function e(){let t="";for(var e,r;(e=E(d.charCodeAt(l)))||(r=d.charCodeAt(l))===h||r>=O&&r<=N||r===J||r===S||r===j;)t+=e?d[l]:" ",l++;return 0<t.length&&(s+=t,!0)}function i(t){return d.charCodeAt(l)===t&&(s+=d[l],l++,!0)}function C(){92===d.charCodeAt(l)&&l++}function g(t){t=0<arguments.length&&void 0!==t&&t;let e=92===d.charCodeAt(l);if(e&&(l++,e=!0),R(d.charCodeAt(l))){const h=F(d.charCodeAt(l))?F:z(d.charCodeAt(l))?z:q(d.charCodeAt(l))?q:U;for(var r=l,n=s,o=(s+='"',l++,t?t=>m(d[t]):t=>h(d.charCodeAt(t)));l<d.length&&!o(l);){if(92===d.charCodeAt(l)){var c=d.charAt(l+1);if(void 0!==L[c])s+=d.slice(l,l+2),l+=2;else if("u"===c){if(!(I(d.charCodeAt(l+2))&&I(d.charCodeAt(l+3))&&I(d.charCodeAt(l+4))&&I(d.charCodeAt(l+5)))){i=void 0;var i=l;let t=i+2;for(;/\w/.test(d[t]);)t++;i=d.slice(i,t);throw new v(`Invalid unicode character "${i}"`,l)}s+=d.slice(l,l+6),l+=6}else s+=c,l+=2}else{var f,i=d.charAt(l),c=d.charCodeAt(l);if(c===$&&92!==d.charCodeAt(l-1))s+="\\"+i;else if((f=c)===b||f===w||f===p||f===x||f===y)s+=K[i];else{if(!(32<=(f=c)&&f<=1114111))throw f=void 0,f=i,new v("Invalid character "+JSON.stringify(f),l);s+=i}l++}e&&C()}var u=R(d.charCodeAt(l));if(!(u&&(l+1>=d.length||m(function(t,e){let r=e;for(;E(t.charCodeAt(r));)r++;return t.charAt(r)}(d,l+1))))&&!t)return l=r,s=n,g(!0);u?(s+='"',l++):s=D(s,'"');{let t=!1;A();for(;43===d.charCodeAt(l);){t=!0,l++,A();var a=(s=B(s,'"',!0)).length;g(),s=function(t,e,r){return t.substring(0,e)+t.substring(e+r)}(s,a,1)}t}return!0}return!1}function r(t,e){return d.slice(l,l+t.length)===t&&(s+=e,l+=t.length,!0)}function f(){for(var t=l;l<d.length&&!m(d[l]);)l++;if(l>t){if(40===d.charCodeAt(l))l++,c(),41===d.charCodeAt(l)&&(l++,59===d.charCodeAt(l))&&l++;else{for(;E(d.charCodeAt(l-1))&&0<l;)l--;t=d.slice(t,l);s+="undefined"===t?"null":JSON.stringify(t),d.charCodeAt(l)===$&&l++}return!0}}function n(t){if(!k(d.charCodeAt(l)))throw t=d.slice(t,l),new v(`Invalid number '${t}', expecting a digit `+(d[l]?`but got '${d[l]}'`:"but reached end of input"),l)}function o(t){if(l>=d.length)return s+=d.slice(t,l)+"0",1;n(t)}function u(){throw new v("Colon expected",l)}}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).JSONRepair={})}(this,function(t){"use strict";class p extends Error{constructor(t,e){super(t+" at position "+e),this.position=e}}const a=125,e=32,w=10,x=9,y=13,$=8,O=12,N=34,r=39,J=48,S=57,j=65,I=97,k=70,m=102,h=160,d=8192,l=8202,T=8239,E=8287,R=12288,n=8220,o=8221,c=8216,i=8217,f=96,u=180;function U(t){return t>=J&&t<=S}function F(t){return s.test(t)||t&&B(t.charCodeAt(0))}const s=/^[,:[\]{}()\n+]$/;function q(t){return A.test(t)||t&&B(t.charCodeAt(0))}const A=/^[[{\w-]$/;function z(t){return t===e||t===w||t===x||t===y}function B(t){return D(t)||H(t)}function D(t){return t===N||t===n||t===o}function G(t){return t===N}function H(t){return t===r||t===c||t===i||t===f||t===u}function K(t){return t===r}function L(t,e,r){r=2<arguments.length&&void 0!==r&&r,e=t.lastIndexOf(e);return-1!==e?t.substring(0,e)+(r?"":t.substring(e+1)):t}function M(t,e){let r=t.length;if(!z(t.charCodeAt(r-1)))return t+e;for(;z(t.charCodeAt(r-1));)r--;return t.substring(0,r)+e+t.substring(r)}const P={"\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t"},Q={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};t.JSONRepairError=p,t.jsonrepair=function(s){let A=0,C="";if(!c())throw new p("Unexpected end of json string",s.length);var t=i(44);if(t&&g(),q(s[A])&&/[,\n][ \t\r]*$/.test(C)){t||(C=M(C,","));{let t=!0,e=!0;for(;e;)t?t=!1:i(44)||(C=M(C,",")),e=c();e||(C=L(C,","));C=`[ | ||
${C} | ||
]`}}else t&&(C=L(C,","));for(;s.charCodeAt(A)===a||93===s.charCodeAt(A);)A++,g();if(A>=s.length)return C;throw new p("Unexpected character "+JSON.stringify(s[A]),A);function c(){g();var t=function(){if(123!==s.charCodeAt(A))return!1;{C+="{",A++,g();let e=!0;for(;A<s.length&&s.charCodeAt(A)!==a;){let t;if(e?(t=!0,e=!1):((t=i(44))||(C=M(C,",")),g()),!(b()||f())){s.charCodeAt(A)===a||123===s.charCodeAt(A)||93===s.charCodeAt(A)||91===s.charCodeAt(A)||void 0===s[A]?C=L(C,","):function(){throw new p("Object key expected",A)}();break}g();var r=i(58),n=A>=s.length,o=(r||(q(s[A])||n?C=M(C,":"):u()),c());o||(r||n?C+="null":u())}return s.charCodeAt(A)===a?(C+="}",A++):C=M(C,"}"),!0}}()||function(){if(91!==s.charCodeAt(A))return!1;{C+="[",A++,g();let t=!0;for(;A<s.length&&93!==s.charCodeAt(A);){t?t=!1:i(44)||(C=M(C,","));var e=c();if(!e){C=L(C,",");break}}return 93===s.charCodeAt(A)?(C+="]",A++):C=M(C,"]"),!0}}()||b()||function(){var t=A;if(45===s.charCodeAt(A)&&(A++,o(t)))return!0;for(;U(s.charCodeAt(A));)A++;if(46===s.charCodeAt(A)){if(A++,o(t))return!0;for(;U(s.charCodeAt(A));)A++}if(101===s.charCodeAt(A)||69===s.charCodeAt(A)){if(A++,45!==s.charCodeAt(A)&&43!==s.charCodeAt(A)||A++,o(t))return!0;for(;U(s.charCodeAt(A));)A++}{var e;if(A>t)return t=s.slice(t,A),e=/^0\d/.test(t),C+=e?`"${t}"`:t,!0}return!1}()||r("true","true")||r("false","false")||r("null","null")||r("True","true")||r("False","false")||r("None","null")||f();return g(),t}function g(){A;let t=e();for(;t=(t=function(){if(47===s.charCodeAt(A)&&42===s.charCodeAt(A+1)){for(;A<s.length&&!function(t,e){return"*"===t[e]&&"/"===t[e+1]}(s,A);)A++;A+=2}else{if(47!==s.charCodeAt(A)||47!==s.charCodeAt(A+1))return!1;for(;A<s.length&&s.charCodeAt(A)!==w;)A++}return!0}())&&e(););A}function e(){let t="";for(var e,r;(e=z(s.charCodeAt(A)))||(r=s.charCodeAt(A))===h||r>=d&&r<=l||r===T||r===E||r===R;)t+=e?s[A]:" ",A++;return 0<t.length&&(C+=t,!0)}function i(t){return s.charCodeAt(A)===t&&(C+=s[A],A++,!0)}function v(){92===s.charCodeAt(A)&&A++}function b(t){var e,t=0<arguments.length&&void 0!==t&&t;let r=92===s.charCodeAt(A);if(r&&(A++,r=!0),B(s.charCodeAt(A))){const l=G(s.charCodeAt(A))?G:K(s.charCodeAt(A))?K:H(s.charCodeAt(A))?H:D;for(var n=A,o=C,c=(C+='"',A++,t?t=>F(s[t]):t=>l(s.charCodeAt(t)));A<s.length&&!c(A);){if(92===s.charCodeAt(A)){var i=s.charAt(A+1);if(void 0!==Q[i])C+=s.slice(A,A+2),A+=2;else if("u"===i){let t=2;for(;t<6&&((e=s.charCodeAt(A+t))>=J&&e<=S||e>=j&&e<=k||e>=I&&e<=m);)t++;if(6===t)C+=s.slice(A,A+6),A+=6;else{if(!(t<6&&A+t>=s.length))throw u=a=void 0,a=A,u=s.slice(a,a+6),new p(`Invalid unicode character "${u}"`,a);A=s.length}}else C+=i,A+=2}else{var f,u=s.charAt(A),a=s.charCodeAt(A);if(a===N&&92!==s.charCodeAt(A-1))C+="\\"+u;else if((i=a)===w||i===y||i===x||i===$||i===O)C+=P[u];else{if(!(32<=(f=a)&&f<=1114111))throw f=void 0,f=u,new p("Invalid character "+JSON.stringify(f),A);C+=u}A++}r&&v()}var h=B(s.charCodeAt(A));if(!(h&&(A+1>=s.length||F(function(t,e){let r=e;for(;z(t.charCodeAt(r));)r++;return t.charAt(r)}(s,A+1))))&&!t)return A=n,C=o,b(!0);h?(C+='"',A++):C=M(C,'"');{let t=!1;g();for(;43===s.charCodeAt(A);){t=!0,A++,g();var d=(C=L(C,'"',!0)).length;b(),C=function(t,e,r){return t.substring(0,e)+t.substring(e+r)}(C,d,1)}t}return!0}return!1}function r(t,e){return s.slice(A,A+t.length)===t&&(C+=e,A+=t.length,!0)}function f(){for(var t=A;A<s.length&&!F(s[A]);)A++;if(A>t){if(40===s.charCodeAt(A))A++,c(),41===s.charCodeAt(A)&&(A++,59===s.charCodeAt(A))&&A++;else{for(;z(s.charCodeAt(A-1))&&0<A;)A--;t=s.slice(t,A);C+="undefined"===t?"null":JSON.stringify(t),s.charCodeAt(A)===N&&A++}return!0}}function n(t){if(!U(s.charCodeAt(A)))throw t=s.slice(t,A),new p(`Invalid number '${t}', expecting a digit `+(s[A]?`but got '${s[A]}'`:"but reached end of input"),A)}function o(t){if(A>=s.length)return C+=s.slice(t,A)+"0",1;n(t)}function u(){throw new p("Colon expected",A)}}}); |
{ | ||
"name": "jsonrepair", | ||
"version": "3.4.0", | ||
"version": "3.4.1", | ||
"description": "Repair broken JSON documents", | ||
@@ -33,4 +33,4 @@ "repository": { | ||
"scripts": { | ||
"test": "mocha", | ||
"test:it": "mocha test-lib/*.test.*", | ||
"test": "vitest watch src", | ||
"test:it": "vitest run src", | ||
"build": "npm-run-all build:**", | ||
@@ -43,6 +43,7 @@ "build:clean": "del-cli lib", | ||
"build:types": "tsc --project tsconfig-types.json", | ||
"build:validate": "vitest run test-lib", | ||
"lint": "eslint src/**/*.ts", | ||
"format": "npm run lint -- --fix", | ||
"benchmark": "npm run build:esm && node tools/benchmark/run.mjs", | ||
"build-and-test": "npm run lint && npm run build && npm run test:it", | ||
"build-and-test": "npm run lint && npm run test:it && npm run build", | ||
"release": "npm-run-all release:**", | ||
@@ -69,8 +70,7 @@ "release:build-and-test": "npm run build-and-test", | ||
"@babel/preset-typescript": "7.23.2", | ||
"@commitlint/cli": "18.0.0", | ||
"@commitlint/config-conventional": "18.0.0", | ||
"@types/mocha": "10.0.3", | ||
"@types/node": "20.8.7", | ||
"@typescript-eslint/eslint-plugin": "6.8.0", | ||
"@typescript-eslint/parser": "6.8.0", | ||
"@commitlint/cli": "18.2.0", | ||
"@commitlint/config-conventional": "18.1.0", | ||
"@types/node": "20.8.10", | ||
"@typescript-eslint/eslint-plugin": "6.9.1", | ||
"@typescript-eslint/parser": "6.9.1", | ||
"benchmark": "2.1.4", | ||
@@ -86,11 +86,11 @@ "cpy-cli": "5.0.0", | ||
"husky": "8.0.3", | ||
"mocha": "10.2.0", | ||
"npm-run-all": "4.1.5", | ||
"prettier": "3.0.3", | ||
"rollup": "4.1.4", | ||
"rollup": "4.2.0", | ||
"standard-version": "9.5.0", | ||
"ts-node": "10.9.1", | ||
"typescript": "5.2.2", | ||
"uglify-js": "3.17.4" | ||
"uglify-js": "3.17.4", | ||
"vitest": "0.34.6" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
260985
28
2415