gpt4 book ai didi

javascript - url 解码复杂字符串给出 "URI malformed"错误

转载 作者:行者123 更新时间:2023-12-03 08:04:57 26 4
gpt4 key购买 nike

如何解码该字符串:

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(在 shell 中运行的 AngularJS 测试实用程序)的输出,看起来像是经过 url 编码的。我 tried to decode it in jsFiddle 使用 javascript decodeURIComponent 函数,但它不起作用并抛出错误(在检查器中可见)“URI 格式错误”。该字符串实际上并不是一个 URI,而是一组嵌套的 URI 和文本,并且已进行编码。

如何解码?

最佳答案

您首先需要通过删除所有新行来“清理”您的字符串

现场演示: 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)

关于javascript - url 解码复杂字符串给出 "URI malformed"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34423589/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com