include/punk/punk_escape.h

filter: Statementstmt 100% 14 / 14 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 100% 20 / 20 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Punk/WebSocket/Room.pm ↑ Summary xs/wshandshake.xs »
1 #ifndef PUNK_ESCAPE_H
2 #define PUNK_ESCAPE_H
3  
4 /* Escape text for HTML: an element's content or an attribute's value, quoted
5 * either way. Appends to `out`, copying runs that need nothing in one go.
6 *
7 * The five characters are the whole job: & < > " ' are the only ones that can
8 * end a text node, an attribute value or a tag. Bytes are copied as they are,
9 * so UTF-8 passes through untouched (no byte of a multi-byte character is
10 * ASCII). The csrf field, the static listing and the markdown mount all write
11 * markup with this; $c->escape_html is the same function for Perl. XML is a
12 * different escape (the sitemap's &apos;) and has its own. */
13 9179 static void punk_html_escape(pTHX_ SV *out, const char *s, STRLEN len) {
14 9179 STRLEN i, run = 0;
15 98839 ▶ for (i = 0; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; i++) { 89660 9179 98839
16 const char *rep;
17 89660 switch (s[i]) {
18 9 case '&': rep = "&amp;"; break;
19 29 case '<': rep = "&lt;"; break;
20 27 case '>': rep = "&gt;"; break;
21 22 case '"': rep = "&quot;"; break;
22 3 case '\'': rep = "&#39;"; break;
23 89570 default: run++; continue;
24 }
25 90 ▶ if (run) { sv_catpvn(out, s + i - run, run); run = 0; }
Branch: 1 branch
BranchTrueFalseTotal
if (run) { sv_catpvn(out, s + i - run, run); run = 0; } 77 13 90
26 90 sv_catpv(out, rep);
27 }
28 9179 ▶ if (run) sv_catpvn(out, s + len - run, run);
Branch: 1 branch
BranchTrueFalseTotal
if (run) sv_catpvn(out, s + len - run, run); 8747 432 9179
29 9179 }
30  
31 #endif
« blib/lib/Punk/WebSocket/Room.pm ↑ Summary xs/wshandshake.xs »