Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML escape #51

Merged
merged 8 commits into from
Feb 3, 2015
Merged

HTML escape #51

merged 8 commits into from
Feb 3, 2015

Conversation

jodosha
Copy link
Member

@jodosha jodosha commented Jan 15, 2015

Feature

Escape utilities for HTML contents and attributes

HTML escape utilities
Based on OWASP research and OWASP ESAPI code

See:
https://www.owasp.org
https://www.owasp.org/index.php/Cross-site_Scripting_%28XSS%29
https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet
https://www.owasp.org/index.php/ESAPI
https://github.com/ESAPI/esapi-java-legacy

Ref: hanami/helpers#7

Technical notes

Lookup chars

It internally uses Hash instances to lookup chars.

They are implemented with this syntax { 0x9f => true }, which makes them equivalent to Set.new([0x9f]), but the lookup is faster: https://gist.github.com/jodosha/ac5dd54416de744b9600

Output class

The output is a Lotus::Utils::Escape::SafeString instance. This is a private class that is required for two reasons:

  • Don't double escape the same string (this is for Lotus::Helpers compatibility)
  • Leave open the possibility to developers to mark a string as safe with an higher API (eg. #raw in Lotus::View or Lotus::Helpers)

@jodosha jodosha self-assigned this Jan 15, 2015
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 84e3bae on html-escape into * on master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling cace05a on html-escape into * on master*.

@stevehodgkiss
Copy link

Looks great, and easy enough to follow...

# @since x.x.x
# @api private
#
# @see http://www.ruby-doc.org/Fixnum.html#method-i-to_s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Page not found, the message in the web:

We're sorry, but that page cannot be found.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlfonsoUceda Fixed, thanks 👍

@AlfonsoUceda
Copy link
Contributor

👍 @jodosha I learn a lot reading your code ;) and tomorrow I'll see the references posted above.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling f5fc4cc on html-escape into * on master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling bc940ba on html-escape into * on master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling d9225cb on html-escape into * on master*.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.97%) to 98.87% when pulling abc1262 on html-escape into 0971592 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.89%) to 98.8% when pulling 0e99a90 on html-escape into 0971592 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.92%) to 98.82% when pulling e99473d on html-escape into 0971592 on master.

@jodosha jodosha merged commit e99473d into master Feb 3, 2015
@jodosha jodosha added the feature label Feb 3, 2015
@jodosha jodosha deleted the html-escape branch March 13, 2015 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants