#179 ✓resolved
yuanyi

格式化用户提交的HTML代码

Reported by yuanyi | 2009-10-24 00:24:01 UTC | in 1.0.7

参看这个: http://www.1kg.org/shares/1000581

用户提交的错误HTML代码导致样式页面样式错误.

doc = Nokogiri::HTML.parse("

hello world

")
doc.at("/html/body").inner_html
=> "

hello world

"

Comments and changes to this ticket

  • suave

    suave 2009-11-05 17:12:30 UTC

    • Milestone changed from “1.0.4” to “1.0.5”

    [milestone:id#54873 bulk edit command]

  • yuanyi

    yuanyi 2009-11-22 23:45:19 UTC

    • Milestone changed from “1.0.5” to “1.0.6”
  • suave

    suave 2009-12-02 10:15:55 UTC

    • Milestone changed from “1.0.6” to “1.0.7”
  • suave

    suave 2009-12-02 19:59:45 UTC

    这个 ticket 是不是和头像 load 慢引发的过滤FCK编辑器提交内容一样

    最后实施的方案请 comment 一下

  • yuanyi

    yuanyi 2009-12-03 10:05:56 UTC

    • Assigned user set to “yuanyi”

    用Sanitize试了一下,效果很好,测试的Filter是:

    Sanitize.clean(@share.body_html, :elements => ['a', 'div', 'img', 'p', 'embed'],
                            :attributes => {'a' => ['href', 'title'], 'img' => ['src', 'alt', 'title']},
                            :protocols => {'a' => {'href' => ['http', 'https', 'mailto']}})
    

    不知道有没遗漏的标签?

  • suave

    suave 2009-12-03 11:31:22 UTC

    在FCK的编辑器里面把各种样式都选一下,看看生成的代码就知道了。

    好像会生成 style attr

  • yuanyi

    yuanyi 2009-12-03 11:42:22 UTC

    加上了FCK的标签,现在是,p也有style,但是是用来左右对齐的,貌似没有这个需求,先不加了:

    Sanitize.clean(html, :elements => ['a', 'div', 'span', 'img', 'p', 'embed', 'em', 'ol', 'ul', 'li'],
              :attributes => {'a' => ['href', 'title'], 'img' => ['src', 'alt', 'title'], 'span' => ['style']},
              :protocols => {'a' => {'href' => ['http', 'https', 'mailto']}})
    
  • yuanyi

    yuanyi 2009-12-03 11:45:20 UTC

    这个改动较大,部署到Dev了,等加上测试后再部署到Master

  • yuanyi

    yuanyi 2009-12-03 11:59:26 UTC

    • State changed from “new” to “resolved”

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Pages