尖括号 (<>) 之间的字符在数据库中被删除?
我想将 mysql 正则表达式存储到 mysql 数据库字段。具体来说,我想将单词边界表达式存储到数据库中。例如:
[[:<:]]my expression here[[:>:]]
如果我将此值直接放入数据库(例如使用 Sequel Pro),则该值将正确存储。
当我想通过 Ruby on Rails 存储这个值时出现问题:
my_instance.sql_expression = "[[:<:]]my expression here[[:>:]]"
my_instance.save
=> true
但实际存储到数据库的值看起来像这样:
my_instance.sql_expression
=> "[[::]]"
似乎在字符串 Rails 中忽略了“<”之间的所有内容和“>”包括标志本身。
该项目使用 Ruby 1.8.7 和 Rails 2.3.5。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这听起来像是您在保存模型之前使用 xss_terminate 之类的东西来过滤模型。我会在您的模型定义中查找具有
before_save
或其他可能会侵入性执行此操作的挂钩的内容。这不是标准的 Rails 行为。
This sounds like you're using something like xss_terminate to filter your models before saving them. I'd look in your model definition for something which has a
before_save
or other hook that might be intrusively doing this.This is not standard Rails behavior.