Sha256: 5e18fefb917f322e22bf5f78a788f81a0d9502ae7e2d8ada2e263d1f02c7cfc7

Contents?: true

Size: 2 KB

Versions: 68

Compression:

Stored size: 2 KB

Contents

#include <assert.h>
#include <stdio.h>
#include <string.h>

#include "houdini.h"

#define ESCAPE_GROW_FACTOR(x) (((x) * 12) / 10) /* this is very scientific, yes */

/**
 * According to the OWASP rules:
 *
 * & --> &amp;
 * < --> &lt;
 * > --> &gt;
 * " --> &quot;
 * ' --> &#x27;     &apos; is not recommended
 * / --> &#x2F;     forward slash is included as it helps end an HTML entity
 *
 */
static const char HTML_ESCAPE_TABLE[] = {
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 1, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 0, 4, 
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 6, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};

static const char *HTML_ESCAPES[] = {
        "",
        "&quot;",
        "&amp;",
        "&#39;",
        "&#47;",
        "&lt;",
        "&gt;"
};

void
houdini_escape_html0(struct buf *ob, const uint8_t *src, size_t size, int secure)
{
	size_t i = 0, org, esc = 0;

	bufgrow(ob, ESCAPE_GROW_FACTOR(size));

	while (i < size) {
		org = i;
		while (i < size && (esc = HTML_ESCAPE_TABLE[src[i]]) == 0)
			i++;

		if (i > org)
			bufput(ob, src + org, i - org);

		/* escaping */
		if (i >= size)
			break;

		/* The forward slash is only escaped in secure mode */
		if (src[i] == '/' && !secure) {
			bufputc(ob, '/');
		} else {
			bufputs(ob, HTML_ESCAPES[esc]);
		}

		i++;
	}
}

void
houdini_escape_html(struct buf *ob, const uint8_t *src, size_t size)
{
	houdini_escape_html0(ob, src, size, 1);
}

Version data entries

68 entries across 65 versions & 9 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/github-markdown-0.6.9/ext/markdown/houdini_html_e.c
tdiary-5.0.5 vendor/bundle/gems/github-markdown-0.6.9/ext/markdown/houdini_html_e.c
tdiary-5.0.4 vendor/bundle/gems/github-markdown-0.6.9/ext/markdown/houdini_html_e.c
redsnow-0.4.4 ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.c
lounge_lizard-0.1.4 ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.c
lounge_lizard-0.1.3 ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.c
lounge_lizard-0.1.2 ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.c
lounge_lizard-0.1.1 ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.c
lounge_lizard-0.1.0 ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.c
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/github-markdown-0.6.9/ext/markdown/houdini_html_e.c
github-markdown-0.6.9 ext/markdown/houdini_html_e.c
redsnow-0.4.3 ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.c
redsnow-0.4.1 ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.c
redsnow-0.4.0 ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.c
redsnow-0.3.7 ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.c
redsnow-0.3.4 ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.c
github-markdown-0.6.8 ext/markdown/houdini_html_e.c
redsnow-0.3.3 ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.c
redsnow-0.3.2 ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.c
redsnow-0.3.1 ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.c