url-解码复杂字符串会出现 "URI malformed" 错误
url-decoding a complex string gives "URI malformed" error
如何解码这个字符串:
Error: [$injector:modulerr] http://errors.angularjs.org/1.4.5/$injector/modulerr?p0=app&p1=Error%3A%20%5B%24injector%3Amodulerr%5D%20http%3A%2F%2Ferrors.angu
larjs.org%2F1.4.5%2F%24injector%2Fmodulerr%3Fp0%3DngRoute%26p1%3DError%253A%2520%255B%2524injector%253Anomod%255D%2520http%253A%252F%252Ferrors.angularjs.org%252F1.4
.5%252F%2524injector%252Fnomod%253Fp0%253DngRoute%250A%2520%2520%2520%2520at%2520Error%2520(native)%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A9
876%252FI:/xampp/htdocs/apps/ng/ng-new%252Ftests%252Fangular.min.js%253F6dc1d8ac54104c214e3d5b22f00668da73033e0e%253A6%253A416%250A%2520%2520%2520%2520at%2520http%
253A%252F%252Flocalhost%253A9876%252Fbase%252Ftests%252Fangular.min.js%253F6dc1d8ac54104c214e3d5b22f00668da73033e0e%253A24%253A605%250A%2520%2520%2520%2520at%2520a%2
520(http%253A%252F%252Flocalhost%253A9876%252Fbase%252Ftests%252Fangular.min.js%253F6dc1d8ac54104c214e3d5b22f00668da73033e0e%253A23%253A149)%250A%2520%2520%2520%2520
at%2520http%253A%252F%252Flocalhost%253A9876%252Fbase%252Ftests%252Fangular.min.js%253F6dc1d8ac54104c214e3d5b22f00668da73033e0e%253A23%253A392%250A%2520%2520%2520%25
20at%2520http%253A%252F%252Flocalhost%253A9876%252Fbase%252Ftests%252Fangular.min.js%253F6dc1d8ac54104c214e3d5b22f00668da73033e0e%253A37%253A340%250A%2520%2520%2520%
2520at%2520n%2520(http%253A%252F%252Flocalhost%253A9876%252Fbase%252Ftests%252Fangular.min.js%253F6dc1d8ac54104c214e3d5b22f00668da73033e0e%253A7%253A326)%250A%2520%2
520%2520%2520at%2520g%2520(http%253A%252F%252Flocalhost%253A9876%252Fbase%252Ftests%252Fangular.min.js%253F6dc1d8ac54104c214e3d5b22f00668da73033e0e%253A37%253A188)%2
50A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A9876%252Fbase%252Ftests%252Fangular.min.js%253F6dc1d8ac54104c214e3d5b22f00668da73033e0e%253A37%253A357
%250A%2520%2520%2520%2520at%2520n%2520(http%253A%252F%252Flocalhost%253A9876%252Fbase%252Ftests%252Fangular.min.js%253F6dc1d8ac54104c214e3d5b22f00668da73033e0e%253A7
%253A326)%0A%20%20%20%20at%20Error%20(native)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da7303
3e0e%3A6%3A416%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A38%3A106%0A%20%20%20%20a
t%20n%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A7%3A326)%0A%20%20%20%20at%20g%20(http%3A%2F%2Floc
alhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A37%3A188)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%
2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A37%3A357%0A%20%20%20%20at%20n%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8
ac54104c214e3d5b22f00668da73033e0e%3A7%3A326)%0A%20%20%20%20at%20g%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668d
a73033e0e%3A37%3A188)%0A%20%20%20%20at%20Object.eb%20%5Bas%20injector%5D%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f
00668da73033e0e%3A40%3A443)%0A%20%20%20%20at%20Object.workFn%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular-mocks.js%3Faaf67bb530e29948531b786e45637c71c44
19891%3A2428%3A64)
它是 Karma(AngularJS 测试实用程序 运行 in shell)的输出,它看起来像是 url 编码的。我 tried to decode it in jsFiddle 使用 javascript decodeURIComponent
函数,但它不起作用并抛出错误(在 Inspector 中可见)"URI malformed"。该字符串实际上不是 URI,而是一组嵌套的 URI 和文本,并且已编码。
如何解码?
删除消息中的换行符后,decodeURIComponent
正常工作,returns:
Error: [$injector:modulerr] http://errors.angularjs.org/1.4.5/$injector/modulerr?p0=app&p1=Error: [$injector:modulerr] http://errors.angularjs.org/1.4.5/$injector/modulerr?p0=ngRoute&p1=Error%3A…ests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A7%3A326)
at Error (native)
at http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:6:416
at http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:38:106
at n (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:7:326)
at g (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:37:188)
at http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:37:357
at n (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:7:326)
at g (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:37:188)
at Object.eb [as injector] (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:40:443)
at Object.workFn (http://localhost:9876/base/tests/angular-mocks.js?aaf67bb530e29948531b786e45637c71c4419891:2428:64)
您首先需要 "sanitize" 您的 string
删除所有新行。
现场演示: https://jsfiddle.net/oscarj24/4wvtdreg/
angular.module('myapp', []).controller('Decoder', ['$scope', function($scope) {
$scope.decode = function() {
var str = this.src;
str = str.replace(/(\r\n|\n|\r)/gm, '');
this.src = decodeURIComponent(str);
}
}]);
(我是根据下面的answer)
之后你将得到正确的输出:
Error: [$injector:modulerr] http://errors.angularjs.org/1.4.5/$injector/modulerr?p0=app&p1=Error: [$injector:modulerr] http://errors.angularjs.org/1.4.5/$injector/modulerr?p0=ngRoute&p1=Error%3A%20%5B%24injector%3Anomod%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.4.5%2F%24injector%2Fnomod%3Fp0%3DngRoute%0A%20%20%20%20at%20Error%20(native)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2FI:/xampp/htdocs/apps/ng/ng-new%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A6%3A416%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A24%3A605%0A%20%20%20%20at%20a%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A23%3A149)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A23%3A392%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A37%3A340%0A%20%20%20%20at%20n%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A7%3A326)%0A%20%20%20%20at%20g%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A37%3A188)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A37%3A357%0A%20%20%20%20at%20n%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A7%3A326)
at Error (native)
at http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:6:416
at http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:38:106
at n (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:7:326)
at g (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:37:188)
at http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:37:357
at n (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:7:326)
at g (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:37:188)
at Object.eb [as injector] (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:40:443)
at Object.workFn (http://localhost:9876/base/tests/angular-mocks.js?aaf67bb530e29948531b786e45637c71c4419891:2428:64)
如何解码这个字符串:
Error: [$injector:modulerr] http://errors.angularjs.org/1.4.5/$injector/modulerr?p0=app&p1=Error%3A%20%5B%24injector%3Amodulerr%5D%20http%3A%2F%2Ferrors.angu
larjs.org%2F1.4.5%2F%24injector%2Fmodulerr%3Fp0%3DngRoute%26p1%3DError%253A%2520%255B%2524injector%253Anomod%255D%2520http%253A%252F%252Ferrors.angularjs.org%252F1.4
.5%252F%2524injector%252Fnomod%253Fp0%253DngRoute%250A%2520%2520%2520%2520at%2520Error%2520(native)%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A9
876%252FI:/xampp/htdocs/apps/ng/ng-new%252Ftests%252Fangular.min.js%253F6dc1d8ac54104c214e3d5b22f00668da73033e0e%253A6%253A416%250A%2520%2520%2520%2520at%2520http%
253A%252F%252Flocalhost%253A9876%252Fbase%252Ftests%252Fangular.min.js%253F6dc1d8ac54104c214e3d5b22f00668da73033e0e%253A24%253A605%250A%2520%2520%2520%2520at%2520a%2
520(http%253A%252F%252Flocalhost%253A9876%252Fbase%252Ftests%252Fangular.min.js%253F6dc1d8ac54104c214e3d5b22f00668da73033e0e%253A23%253A149)%250A%2520%2520%2520%2520
at%2520http%253A%252F%252Flocalhost%253A9876%252Fbase%252Ftests%252Fangular.min.js%253F6dc1d8ac54104c214e3d5b22f00668da73033e0e%253A23%253A392%250A%2520%2520%2520%25
20at%2520http%253A%252F%252Flocalhost%253A9876%252Fbase%252Ftests%252Fangular.min.js%253F6dc1d8ac54104c214e3d5b22f00668da73033e0e%253A37%253A340%250A%2520%2520%2520%
2520at%2520n%2520(http%253A%252F%252Flocalhost%253A9876%252Fbase%252Ftests%252Fangular.min.js%253F6dc1d8ac54104c214e3d5b22f00668da73033e0e%253A7%253A326)%250A%2520%2
520%2520%2520at%2520g%2520(http%253A%252F%252Flocalhost%253A9876%252Fbase%252Ftests%252Fangular.min.js%253F6dc1d8ac54104c214e3d5b22f00668da73033e0e%253A37%253A188)%2
50A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A9876%252Fbase%252Ftests%252Fangular.min.js%253F6dc1d8ac54104c214e3d5b22f00668da73033e0e%253A37%253A357
%250A%2520%2520%2520%2520at%2520n%2520(http%253A%252F%252Flocalhost%253A9876%252Fbase%252Ftests%252Fangular.min.js%253F6dc1d8ac54104c214e3d5b22f00668da73033e0e%253A7
%253A326)%0A%20%20%20%20at%20Error%20(native)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da7303
3e0e%3A6%3A416%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A38%3A106%0A%20%20%20%20a
t%20n%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A7%3A326)%0A%20%20%20%20at%20g%20(http%3A%2F%2Floc
alhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A37%3A188)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%
2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A37%3A357%0A%20%20%20%20at%20n%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8
ac54104c214e3d5b22f00668da73033e0e%3A7%3A326)%0A%20%20%20%20at%20g%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668d
a73033e0e%3A37%3A188)%0A%20%20%20%20at%20Object.eb%20%5Bas%20injector%5D%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f
00668da73033e0e%3A40%3A443)%0A%20%20%20%20at%20Object.workFn%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular-mocks.js%3Faaf67bb530e29948531b786e45637c71c44
19891%3A2428%3A64)
它是 Karma(AngularJS 测试实用程序 运行 in shell)的输出,它看起来像是 url 编码的。我 tried to decode it in jsFiddle 使用 javascript decodeURIComponent
函数,但它不起作用并抛出错误(在 Inspector 中可见)"URI malformed"。该字符串实际上不是 URI,而是一组嵌套的 URI 和文本,并且已编码。
如何解码?
删除消息中的换行符后,decodeURIComponent
正常工作,returns:
Error: [$injector:modulerr] http://errors.angularjs.org/1.4.5/$injector/modulerr?p0=app&p1=Error: [$injector:modulerr] http://errors.angularjs.org/1.4.5/$injector/modulerr?p0=ngRoute&p1=Error%3A…ests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A7%3A326)
at Error (native)
at http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:6:416
at http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:38:106
at n (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:7:326)
at g (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:37:188)
at http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:37:357
at n (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:7:326)
at g (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:37:188)
at Object.eb [as injector] (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:40:443)
at Object.workFn (http://localhost:9876/base/tests/angular-mocks.js?aaf67bb530e29948531b786e45637c71c4419891:2428:64)
您首先需要 "sanitize" 您的 string
删除所有新行。
现场演示: https://jsfiddle.net/oscarj24/4wvtdreg/
angular.module('myapp', []).controller('Decoder', ['$scope', function($scope) {
$scope.decode = function() {
var str = this.src;
str = str.replace(/(\r\n|\n|\r)/gm, '');
this.src = decodeURIComponent(str);
}
}]);
(我是根据下面的answer)
之后你将得到正确的输出:
Error: [$injector:modulerr] http://errors.angularjs.org/1.4.5/$injector/modulerr?p0=app&p1=Error: [$injector:modulerr] http://errors.angularjs.org/1.4.5/$injector/modulerr?p0=ngRoute&p1=Error%3A%20%5B%24injector%3Anomod%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.4.5%2F%24injector%2Fnomod%3Fp0%3DngRoute%0A%20%20%20%20at%20Error%20(native)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2FI:/xampp/htdocs/apps/ng/ng-new%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A6%3A416%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A24%3A605%0A%20%20%20%20at%20a%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A23%3A149)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A23%3A392%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A37%3A340%0A%20%20%20%20at%20n%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A7%3A326)%0A%20%20%20%20at%20g%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A37%3A188)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A37%3A357%0A%20%20%20%20at%20n%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Fangular.min.js%3F6dc1d8ac54104c214e3d5b22f00668da73033e0e%3A7%3A326)
at Error (native)
at http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:6:416
at http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:38:106
at n (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:7:326)
at g (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:37:188)
at http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:37:357
at n (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:7:326)
at g (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:37:188)
at Object.eb [as injector] (http://localhost:9876/base/tests/angular.min.js?6dc1d8ac54104c214e3d5b22f00668da73033e0e:40:443)
at Object.workFn (http://localhost:9876/base/tests/angular-mocks.js?aaf67bb530e29948531b786e45637c71c4419891:2428:64)