Mercurial
comparison markdown_converter/tests/markdown_to_html_test.c @ 221:ce7f4400c2de hg-web
[hg-web] Harden forge and add changeset UI
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Sun, 02 Aug 2026 09:01:24 -0700 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 219:8c9bb0b0759e | 221:ce7f4400c2de |
|---|---|
| 1 #include "markdown_converter/markdown_to_html.h" | |
| 2 | |
| 3 #include <stdio.h> | |
| 4 #include <string.h> | |
| 5 | |
| 6 static int failures = 0; | |
| 7 | |
| 8 static void expect_equal(const char *name, const char *markdown, const char *expected) | |
| 9 { | |
| 10 char *actual = markdown_to_html(markdown); | |
| 11 if (!actual || strcmp(actual, expected) != 0) { | |
| 12 fprintf(stderr, "%s\nexpected: %s\nactual: %s\n", name, expected, actual ? actual : "(null)"); | |
| 13 failures++; | |
| 14 } | |
| 15 markdown_free(actual); | |
| 16 } | |
| 17 | |
| 18 int main(void) | |
| 19 { | |
| 20 expect_equal("normal link", "[link](https://example.com)", | |
| 21 "<p><a href=\"https://example.com\">link</a></p>"); | |
| 22 expect_equal("escape paragraph", "a & <b>", "<p>a & <b></p>"); | |
| 23 expect_equal("escape raw script", "<script>alert('x')</script>", | |
| 24 "<p><script>alert('x')</script></p>"); | |
| 25 expect_equal("reject script link", "[open](javascript:alert)", "<p>open</p>"); | |
| 26 expect_equal("reject data image", "", "<p>preview</p>"); | |
| 27 expect_equal("escape link attribute", "[link](https://example.com/\"x)", | |
| 28 "<p><a href=\"https://example.com/"x\">link</a></p>"); | |
| 29 expect_equal("escape inline code", "`<script>`", "<p><code><script></code></p>"); | |
| 30 | |
| 31 return failures == 0 ? 0 : 1; | |
| 32 } |