这更像是一种“您能确认这是正确的”问题吗,因为我认为我在编写问题的过程中已解决了该问题,但希望对其他有些犹豫的人有所帮助实施DOMPurify。
简洁版本
DOMPurify在前端js文件中像这样导入和使用是否安全/有效:
npm install dompurify --save
import DOMPurify from 'dompurify';
var clean = DOMPurify.sanitize('<img src=x onerror=alert(1)//>', {SAFE_FOR_JQUERY: true});
Run Code Online (Sandbox Code Playgroud)
详细版本
目前,我的主要前端js文件使用以下约定导入:
import ClipboardJS from 'clipboard';
// date-fns functions
import getYear from 'date-fns/get_year';
import getMonth from 'date-fns/get_month';
import getDaysInMonth from 'date-fns/get_days_in_month';
import startOfMonth from 'date-fns/start_of_month';
import getDay from 'date-fns/get_day';
import format from 'date-fns/format';
import Cookies from './js.cookie';
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法:
npm install dompurify --save
import DOMPurify from 'dompurify';
console.log(DOMPurify.sanitize('<img src=x onerror=alert(1)//>', {SAFE_FOR_JQUERY: true}));
console.log(DOMPurify.sanitize('<svg><g/onload=alert(2)//<p>', {SAFE_FOR_JQUERY: true}));
console.log(DOMPurify.sanitize('<p>abc<iframe/\/src=jAva	script:alert(3)>def', {SAFE_FOR_JQUERY: true}));
console.log(DOMPurify.sanitize('<math><mi//xlink:href="data:x,<script>alert(4)</script>">', …Run Code Online (Sandbox Code Playgroud) 我使用以下内容获取YouTube视频的发布日期:
$url = "http://gdata.youtube.com/feeds/api/videos/{$random_text}?v=2&alt=json";
$json = file_get_contents($url);
$json = str_replace('$', '_', $json);
$obj = json_decode($json);
$video_date = $obj->entry->published->_t;
Run Code Online (Sandbox Code Playgroud)
以这种格式输出日期:
2012-10-18t13:04:42.000z
我怎么能在PHP中将其转换为DD/MM/YY格式?
我尝试过以下解决方案:
这是什么时间格式,如何将其转换为标准化的dd/mm/yyyy日期?
$video_date_pre = $obj->entry->published->_t;
// format the video date
$video_date = date_format($video_date_pre, 'd/m/Y');
Run Code Online (Sandbox Code Playgroud)
但我收到错误:
警告:date_format()期望参数1为DateTime ..
谢谢.
更新
可能有必要注意原始源看起来像这样(您可以在其中搜索"已发布"):
http://gdata.youtube.com/feeds/api/videos/eiAx2kqmUpQ?v=2&alt=json
目标
用户登录并在成功授权后,在登录表单所在的同一位置(从MongoDB数据库)加载管理页面:
登录表单>提交[成功]>从表格所在的同一位置的数据库加载的内容
我试过的
我想我知道解决方案中涉及的大部分'位',但是还没能将它们全部放在一起,例如:
template1.tpl
这是一个view包含jQuery 的瓶子,它用于getJSON()与包含route查询MongoDB数据库的瓶子的Python文件(基于点击的元素'href'值)进行通信,因此返回动态内容:
<script>
function loadContent(href){
$.getJSON("/my_route", {cid: href, format: 'json'}, function(results){
$("#content_area").html("");
$("#content_area").append(results.content);
});
}
</script>
Run Code Online (Sandbox Code Playgroud)
my_application.py
@route('/my_route')
def my_function():
# set up connection
dbname = 'my_db_name'
connection = pymongo.MongoClient(os.environ['OPENSHIFT_MONGODB_DB_URL'])
db = connection[dbname]
# get the data sent from the getJSON() request
href = request.GET.cid
# specify collection based on href value
if href =="x" or href=="y" or href=="z":
collection = db.collection1
elif href=="j":
collection = db.collection2
else: …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的对象数组:
var example = [{
"description": "aaa",
"time": "12:15pm"
}, {
"description": "bbb",
"time": "10:10am"
}, {
"description": "ccc",
"time": "4:00pm"
}, {
"description": "ddd",
"time": "6:15pm"
}, {
"description": "eee",
"time": "1:10am"
}, {
"description": "fff",
"time": "5:00pm"
} ];
Run Code Online (Sandbox Code Playgroud)
我想按time价值排序.
example.sort(function (a, b) {
return new Date('1970/01/01 ' + a.time) - new Date('1970/01/01 ' + b.time);
});
console.log(example);
Run Code Online (Sandbox Code Playgroud)
我也一直在提到Mozilla Array.prototype.sort()文档,并尝试了以下似乎不起作用的:
example.sort(function(a, b) {
if (new Date(a.time) > new Date(b.time)) { …Run Code Online (Sandbox Code Playgroud) 我需要在更长的叙述中为多个句子生成唯一的id(多个用户可以在不同的机器上同时执行相同的操作).
我考虑过new Date().getTime()(也许连接一个username)但是因为id是在一个循环中生成而迭代句子,我发现重复创建(因为生成可以在相同的毫秒发生).
所以我现在正在玩:
var random1 = Math.floor((Math.random() * 10000) + 1).toString(36);
var random2 = Math.floor((Math.random() * 10000) + 1);
var random3 = Math.floor((Math.random() * 10000) + 1);
var id = random1 + random2 + random3;
// generates things like:
// 1h754278042
// 58o83798349
// 3ls28055962
Run Code Online (Sandbox Code Playgroud)
但是我想到了(不可否认,作为一个没有考虑过独特/随机/加密问题的人),或许加入三个随机数并不是随机数一个随机数?
生成和连接3个Math.random()值比1 个值更随机Math.random()吗?
这个答案(https://security.stackexchange.com/a/124003)说明:
如果随机生成器确实产生随机数据,那么无关紧要.
但我不确定这是如何适用于Math.random().
编辑:
场景是Web上的客户端而不是安全性,只是为了确保每个句子在数据库中都有唯一的id.
编辑:
我最终实施了:
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000) …Run Code Online (Sandbox Code Playgroud) 刚刚访问了一个大约一个月没有使用的应用程序,发现“Work Sans”字体在 Google Chrome 中无法正常工作。
Chrome 开发者工具控制台中没有错误消息 - 字体似乎没有被应用。
在 Google Chrome 版本 77.0.3865.90(官方版本)(64 位)中查看:
更新 - 在 Chrome 78.0.3904.70 中仍然无法工作
在 Firefox Quantum 69.0.1(64 位)中查看:
超文本标记语言
<head>
<link href="https://fonts.googleapis.com/css?family=Noto+Sans|Roboto+Mono|Work+Sans:400,700&display=swap" rel="stylesheet">
</head>
<p class="testing1">
Chrome Version 77.0.3865.90 (Official Build) (64-bit)
</p>
<p class="testing2">
Chrome Version 77.0.3865.90 (Official Build) (64-bit)
</p>
<p class="testing3">
Chrome Version 77.0.3865.90 (Official Build) (64-bit)
</p>
Run Code Online (Sandbox Code Playgroud)
CSS
.testing1 {
font-family: 'Work Sans', sans-serif;
}
.testing2 {
font-family: 'Roboto Mono', monospace;
}
.testing3 {
font-family: 'Noto Sans', …Run Code Online (Sandbox Code Playgroud) 我正在学习C#并在运行Windows 7的PC上安装了Visual Studio 2012.
我现在可以浏览到该C:\Windows\Microsoft.NET目录.
我的第一个问题是:
Visual Studio是附带.NET目录,还是Visual Studio只访问运行Windows 7的计算机上已存在的目录?
我的第二个相关问题是:
该位置编号最大的文件夹C:\Windows\Microsoft.NET\Framework\是v4.0.30319.这让我感到困惑,因为https://en.wikipedia.org/wiki/.NET_Framework#History表中与Visual Studio 2012相关的版本号是4.5.50709.17929.
那么,如果几周前安装Visual Studio,为什么我没有更高版本号的文件夹呢?
您好,我一直在尝试从node.js向客户端发送文件.我的代码可以工作,但是当客户端转到指定的url(/helloworld/hello.js/test)时,它会传输文件.从谷歌浏览器访问它使文件(.mp3)在播放器中播放.
我的目标是让客户端的浏览器下载文件并询问客户端他想要存储它的位置,而不是在网站上传输它.
http.createServer(function(req, res) {
switch (req.url) {
case '/helloworld/hello.js/test':
var filePath = path.join(__dirname, '/files/output.mp3');
var stat = fileSystem.statSync(filePath);
res.writeHead(200, {
'Content-Type': 'audio/mpeg',
'Content-Length': stat.size
});
var readStream = fileSystem.createReadStream(filePath);
// We replaced all the event handlers with a simple call to readStream.pipe()
readStream.on('open', function() {
// This just pipes the read stream to the response object (which goes to the client)
readStream.pipe(res);
});
readStream.on('error', function(err) {
res.end(err);
});
}
});
Run Code Online (Sandbox Code Playgroud) 期望的行为
使用Sublime Text 3激活.js文件.
实际行为
没有掉毛.
例如,以下显示没有错误:
var x = ""
Run Code Online (Sandbox Code Playgroud)
重现步骤
环境
Tools > SublimeLinter > Lint Mode > "Background"Tools > SublimeLinter > Mark Style > "Fill"在Sublime Text中(安装SublimeLinter和JSHint插件)
在命令行
使用以下命令安装node.js,npm和jshint:
sudo apt-get install nodejs npm
sudo npm install -g jshint
退出并重新启动Sublime Text.
故障排除
在命令行:
hash -r
which jshint
returns
/usr/local/bin/jshint
Run Code Online (Sandbox Code Playgroud)
我也试过这个解决方案(/sf/answers/1484222561/),涉及手动改变路径Preferences > Package Settings > SublimeLinter > …
我在Samsung Galaxy Tab A中的 Chrome浏览器上遇到问题.
我想用Chrome来解决它们Developer Tools.
在平板电脑上,您无法访问Chrome Developer Tools,因此您需要进行设置Remote Debugging.
根据谷歌的官方文档,这个过程基本上应该是:
1)在PC上安装所需的驱动程序,以便识别平板电脑.
2) 通过USB电缆将平板电脑连接到PC.
2) 在PC上,转到Chrome > Developer Tools > Menu > More Tools > Remote devices
平板电脑没有在PC上的chrome中显示为开发人员工具中的设备.
我试过的
我和三星聊天,他们说要安装Smart Switch PC_Setup.exe,这将安装驱动程序,以便可以识别Android设备.
由于这不起作用,我遵循了各种帖子建议并安装:
SAMSUNG_USB_Driver_for_Mobile_Phones.zip (15.3MB)从这里开始
SDK Platform-Tools for Windows (7.16MB)从这里开始
sdk-tools-windows-3859397 (132MB)从这里的页面底部
所有这些都包含exe我不知道如何使用的文件 - 如果我双击它们只是打开和关闭终端.
期望的行为
将平板电脑显示为Chrome开发者工具中的设备.
javascript ×4
.net ×1
bottle ×1
c# ×1
date ×1
datetime ×1
dompurify ×1
getjson ×1
google-fonts ×1
html ×1
jshint ×1
linux-mint ×1
mongodb ×1
node.js ×1
php ×1
python-2.7 ×1
random ×1
sanitization ×1
sorting ×1
sublimetext3 ×1
windows-7 ×1
youtube-api ×1