尖括号 (<>) 之间的字符在数据库中被删除?

发布于 2024-12-20 05:24:02 字数 531 浏览 2 评论 0 原文

我想将 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。

I want to store mysql regular epxression to mysql database field. Specifically I want to store word boundaries expression into the database. For example:

[[:<:]]my expression here[[:>:]]

If I put this value directly into the database (for example using Sequel Pro) the value is stored correctly.

Problem occur when I want to store this value through Ruby on Rails:

my_instance.sql_expression = "[[:<:]]my expression here[[:>:]]"
my_instance.save 
=> true

But value that is actually stored to database looks like this:

my_instance.sql_expression
=> "[[::]]"

It seems that in string Rails ignore everything what is between "<" and ">" including signs itselfs.

The project is in Ruby 1.8.7 and Rails 2.3.5.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸印温柔 2024-12-27 05:24:02

这听起来像是您在保存模型之前使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文