MCPcopy Create free account
hub / github.com/crankyoldgit/IRremoteESP8266 / htmlEscape

Function htmlEscape

src/IRutils.cpp:1092–1118  ·  view source on GitHub ↗

Escape any special HTML (unsafe) characters in a string. e.g. anti-XSS. @param[in] unescaped A String containing text to make HTML safe. @return A string that is HTML safe.

Source from the content-addressed store, hash-verified

1090/// @param[in] unescaped A String containing text to make HTML safe.
1091/// @return A string that is HTML safe.
1092String htmlEscape(const String unescaped) {
1093 String result = "";
1094 uint16_t ulen = unescaped.length();
1095 result.reserve(ulen); // The result will be at least the size of input.
1096 for (size_t i = 0; i < ulen; i++) {
1097 char c = unescaped[i];
1098 switch (c) {
1099 // ';!-"<>=&#{}() are all unsafe.
1100 case '\'': result += F("&apos;"); break;
1101 case ';': result += F("&semi;"); break;
1102 case '!': result += F("&excl;"); break;
1103 case '-': result += F("&dash;"); break;
1104 case '\"': result += F("&quot;"); break;
1105 case '<': result += F("&lt;"); break;
1106 case '>': result += F("&gt;"); break;
1107 case '=': result += F("&#equals;"); break;
1108 case '&': result += F("&amp;"); break;
1109 case '#': result += F("&num;"); break;
1110 case '{': result += F("&lcub;"); break;
1111 case '}': result += F("&rcub;"); break;
1112 case '(': result += F("&lpar;"); break;
1113 case ')': result += F("&rpar;"); break;
1114 default: result += c;
1115 }
1116 }
1117 return result;
1118}
1119
1120/// Convert a nr. of milliSeconds into a Human-readable string.
1121/// e.g. "1 Day 6 Hours 34 Minutes 17 Seconds"

Callers 1

TESTFunction · 0.85

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.68