# Stripping html from form inputs

**URL:** <https://www.ruby-forum.com/t/stripping-html-from-form-inputs/82499>\
**Category:** Rails\
**Created:** [January 19, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/stripping-html-from-form-inputs/82499 "2007-01-19T16:30:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7993a0/32.png) [@Jason\_B](https://www.ruby-forum.com/u/Jason_B)\
**Post date:** [January 19, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/stripping-html-from-form-inputs/82499/1 "2007-01-19T16:30:57Z")

</div>

Ahoy m8ies,

Quick question.

Is there any existing demo code or a library which handles stripping  
unwanted tags from form fields?

Also, a form might allow image tags, but we might want to strip out  
any paramters other than SRC ?

Anohter issue is how handle inputs such as these:

- **1 is less than 2**
- **1 is \< than 2**

In the second case, we need to guess that \< is not opening a tag, and  
convert it to a special character.

Thanks for any ideas or links!

Jasn

---

<div class="post-metadata">

**Author:** ![Jason\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7993a0/32.png) [@Jason\_B](https://www.ruby-forum.com/u/Jason_B)\
**Post date:** [January 19, 2007, 6:26pm UTC](https://www.ruby-forum.com/t/stripping-html-from-form-inputs/82499/2 "2007-01-19T18:26:28Z")

</div>

> Ahoy m8ies,
> 
> Quick question.
> 
> Is there any existing demo code or a library which handles stripping  
> unwanted tags from form fields?

You might look at strip\_links and strip\_tags

[http://api.rubyonrails.com/classes/ActionView/Helpers/TextHelper.html#M000622](http://api.rubyonrails.com/classes/ActionView/Helpers/TextHelper.html#M000622)

Also, look at the tidy library and gem

[http://tidy.sourceforge.net/](http://tidy.sourceforge.net/)

---

<div class="post-metadata">

**Author:** ![Jason\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7993a0/32.png) [@Jason\_B](https://www.ruby-forum.com/u/Jason_B)\
**Post date:** [January 20, 2007, 10:34pm UTC](https://www.ruby-forum.com/t/stripping-html-from-form-inputs/82499/3 "2007-01-20T22:34:33Z")

</div>

> Is there any existing demo code or a library which handles stripping  
> unwanted tags from form fields?
> 
> Also, a form might allow image tags, but we might want to strip out  
> any paramters other than SRC ?

[http://svn.techno-weenie.net/projects/plugins/white\_list/README](http://svn.techno-weenie.net/projects/plugins/white_list/README)

–  
Rick O.  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![Jason\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7993a0/32.png) [@Jason\_B](https://www.ruby-forum.com/u/Jason_B)\
**Post date:** [January 21, 2007, 11:32am UTC](https://www.ruby-forum.com/t/stripping-html-from-form-inputs/82499/4 "2007-01-21T11:32:41Z")

</div>

Wonderful, thanks Rick and Philip
