MCPcopy Create free account
hub / github.com/apache/httpd / ap_escape_html2

Function ap_escape_html2

server/util.c:2131–2182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2129/* ap_escape_uri is now a macro for os_escape_path */
2130
2131AP_DECLARE(char *) ap_escape_html2(apr_pool_t *p, const char *s, int toasc)
2132{
2133 apr_size_t i, j;
2134 char *x;
2135
2136 /* first, count the number of extra characters */
2137 for (i = 0, j = 0; s[i] != '\0'; i++) {
2138 if (i + j > APR_SIZE_MAX - 6) {
2139 abort();
2140 }
2141 if (s[i] == '<' || s[i] == '>')
2142 j += 3;
2143 else if (s[i] == '&')
2144 j += 4;
2145 else if (s[i] == '"')
2146 j += 5;
2147 else if (toasc && !apr_isascii(s[i]))
2148 j += 5;
2149 }
2150
2151 if (j == 0)
2152 return apr_pstrmemdup(p, s, i);
2153
2154 x = apr_palloc(p, i + j + 1);
2155 for (i = 0, j = 0; s[i] != '\0'; i++, j++)
2156 if (s[i] == '<') {
2157 memcpy(&x[j], "&lt;", 4);
2158 j += 3;
2159 }
2160 else if (s[i] == '>') {
2161 memcpy(&x[j], "&gt;", 4);
2162 j += 3;
2163 }
2164 else if (s[i] == '&') {
2165 memcpy(&x[j], "&amp;", 5);
2166 j += 4;
2167 }
2168 else if (s[i] == '"') {
2169 memcpy(&x[j], "&quot;", 6);
2170 j += 5;
2171 }
2172 else if (toasc && !apr_isascii(s[i])) {
2173 char *esc = apr_psprintf(p, "&#%3.3d;", (unsigned char)s[i]);
2174 memcpy(&x[j], esc, 6);
2175 j += 5;
2176 }
2177 else
2178 x[j] = s[i];
2179
2180 x[j] = '\0';
2181 return x;
2182}
2183AP_DECLARE(char *) ap_escape_logitem(apr_pool_t *p, const char *str)
2184{
2185 char *ret;

Callers 6

si_val_urlFunction · 0.85
print_dateFunction · 0.85
si_add_headerFunction · 0.85
val_url_printFunction · 0.85
handle_echoFunction · 0.85
handle_setFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected