gpt4 book ai didi

angularjs - Cordova url 和图像 src 在 Windows 中的 url 前面有 'unsafe'

转载 作者:行者123 更新时间:2023-12-03 07:56:53 26 4
gpt4 key购买 nike

我正在使用 Angular 开发一个 Cordova 应用程序,我正在为 Windows 做一些努力。

我正在尝试这样的事情:

<img ng-src="{{dataDirectory + buildingPhoto.FilenamePhoto}}" class="full-width">

dataDirectory = "ms-appdata:///local"
buildingPhoto.FilenamePhoto = "VOL-00122kaftfoto_thumb.png"

但这只会导致使用此代码的图像损坏:

<img class="full-width" src="unsafe:ms-appdata:///local/VOL-00122kaftfoto_thumb.png" ng-src="ms-appdata:///local/VOL-00122kaftfoto_thumb.png">

我认为 unsafe 意味着前缀被视为不安全,需要将其列入白名单,因此我在 app.js 中添加了这个:

.config(['$compileProvider', function($compileProvider) {

$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|ghttps?|ms-appx|ms-appdata|x-wmapp0):/);
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|ms-appx|ms-appdata|x-wmapp0):|data:image\//);
}])

我还在 index.html 中添加了这个元标记:

<meta http-equiv="Content-Security-Policy" content="ms-appdata *; default-src *; img-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'" />

但它不起作用,所以我有点卡在这里,希望有人能把我推向正确的方向。

最佳答案

使用以下代码将图像 src 白名单修复:

$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|content|blob‌​|ms-appx|ms-appdata|x-wmapp0|unsafe|local):|data:image\//);

还要确保 $compileProvider 在 app.js 中的初始设置之后不会被其他任何地方覆盖,这实际上导致了 Joris 的问题。

关于angularjs - Cordova url 和图像 src 在 Windows 中的 url 前面有 'unsafe',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37748205/

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