Cosmetic changes and typos correction
authorJuliana Rodrigueiro <juliana.rodrigueiro@intra2net.com>
Wed, 26 Jul 2017 21:52:34 +0000 (23:52 +0200)
committerJuliana Rodrigueiro <juliana.rodrigueiro@intra2net.com>
Mon, 17 Sep 2018 08:28:24 +0000 (10:28 +0200)
src/restricted_html.cpp
src/restricted_html.hpp

index 6796d1e..428edca 100644 (file)
@@ -115,7 +115,7 @@ bool link_sanitizer(string &tag)
 }
 
 /**
- * @brief Check if tag is in a whitelist of alowed tags.
+ * @brief Check if tag is in a whitelist of allowed tags.
  * Does not accept a tag containing attributes.
  * Example:
  * <h1> or </p> returns true.
@@ -149,7 +149,7 @@ const string restrict_html(const string &html_code_orig, bool strip)
     string result = "";
 
     vector<string> expected_tags;
-    BOOST_FOREACH(TOKEN s, tokenized)
+    BOOST_FOREACH(const TOKEN &s, tokenized)
     {
         if (!s.second)
         {
@@ -162,7 +162,7 @@ const string restrict_html(const string &html_code_orig, bool strip)
             {
                 result = result + s.first;
                 if (to_lower(s.first).compare("<br>") != 0)
-                    expected_tags.push_back(s.first.insert(1,"/"));
+                    expected_tags.push_back("</"+s.first.substr(1));
                 continue;
             }
             else if (expected_tags.size() > 0 && expected_tags.back().compare(s.first) == 0)
@@ -173,9 +173,10 @@ const string restrict_html(const string &html_code_orig, bool strip)
             }
         }
 
-        if (to_lower(s.first).compare(0, AHREF.size(), AHREF) == 0 && link_sanitizer(s.first))
+        string tag = s.first;
+        if (to_lower(s.first).compare(0, AHREF.size(), AHREF) == 0 && link_sanitizer(tag))
         {
-            result = result + s.first;
+            result = result + tag;
             expected_tags.push_back("</a>");
             continue;
         }
@@ -185,10 +186,12 @@ const string restrict_html(const string &html_code_orig, bool strip)
 
     }
     if (expected_tags.size() > 0) //One or more tags were not closed.
+    {
         BOOST_REVERSE_FOREACH(const string &s, expected_tags)
         {
             result = result + s;
         }
+    }
 
     return result.c_str();
 }
index ed5711e..00140ac 100644 (file)
@@ -54,7 +54,7 @@ namespace I2n
     /**
      * @brief Restricts html code to a small list of allowed tags.
      * The attribute "href" from the tag "a" has its value sanitized and if it
-     * contains unsafe caracters, the tag is stripped.
+     * contains unsafe characters, the tag is stripped.
      * The link sanitizer adds a redirector in case of an acceptable protocol, strip otherwise.
      * Any other attributes found will result in the tag being stripped.
      * Any comments will be excluded.