【问题标题】:asp classic regular expression: string to URL safeasp 经典正则表达式:字符串到 URL 安全
【发布时间】:2014-03-26 17:16:14
【问题描述】:

早上,

我试图创建一个asp“经典”版本的follow jquery/javascript函数来防止恶意代码被输入到数据库中。

当用户在输入字段中输入产品名称时,它会自动更改永久链接 P 的 html 值和隐藏的输入字段。一旦用户点击提交按钮,我希望它在输入数据库之前在服务器端进行验证。

$(".item-name").keyup(function() {
$("p.permlink").empty().html(convertToSlug($(this).val())+".html");
$(".permlink-input").empty().val(convertToSlug($(this).val())+".html");
});


function convertToSlug(Text)
{
return Text
    .toLowerCase()
    .replace(/[^\w ]+/g,'')
    .replace(/ +/g,'-')
    ;
}

我知道的唯一方法是对键盘上的每个字符使用 asp 替换功能。

replace(strItem, "<", "")
replace(strItem, ">", "")
replace(strItem, "/", "")
replace(strItem, "\", "")
... etc etc

问候 谢恩

【问题讨论】:

  • 为什么不能使用 Classic ASP 的 Regex Replace 并像在 Javascript 中所做的那样做? Another post explaining Classic ASP Regex
  • 嗨 Jamie,这就是我所追求的,但我不知道如何使用正则表达式。
  • @Shane 该链接提供了您需要的所有信息,包括RegExResults() 函数。您可能希望将其修改为 Test 而不是 Execute()
  • 如果你进行搜索,你应该能够找到一个清理数据库输入的函数 - 这里有一个 -blogs.iis.net/nazim/archive/2008/04/28/…。我建议您还考虑参数化查询和 - 如果您的数据库支持它们,存储过程。你会在 Stack Overflow 上找到很多关于这两个问题的问题
  • @John 这不是他想要的,如果是的话,我会建议使用参数化查询,而不是链接到一个毫无意义的脚本,因为它会有更多的误报然后很有用.清理输入以防止 SQL 注入和清理输入以删除 HTML 是不同的。这就是为什么像 Jamie 我会推荐 RegEx 解决方案。

标签: javascript jquery regex asp-classic


【解决方案1】:

刚在博客上发现这个和 jquery 一样。 它将字符串转换为 url/seo。似乎工作得很好。

博客没有名字,只有“blogger classicasp”信用在哪里到期。

Function isURL(strURL)

Dim Slug, re, re2

'Everything to lower case
Slug = lcase(strURL)

' Replace - with empty space
Slug = Replace(Slug, "-", " ")

' Replace unwanted characters with space
Set re = New RegExp
re.Pattern = "[^a-z0-9\s-]"
re.Global = True
Slug = re.Replace(Slug, " ")

' Replace multple white spaces with single space
Set re2 = New RegExp
re2.Pattern = "\s+"
re2.Global = True
Slug = re2.Replace(Slug, " ")

Slug = Trim(Slug)

' Replace white space with -
Slug = Replace(Slug," ", "-")

isURL = Slug

End Function

【讨论】:

    猜你喜欢
    • 2012-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多