Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update Sundown to latest version

c744346e50..b6b58da3ff
minimal changes, APIs affected (broken):

 - autolink

none of the changed APIs are used,
no adaptations required.
  • Loading branch information...
commit 48ef2748d8e038dad08188e48554091af3636f50 1 parent 777ef44
@jmendeth jmendeth authored
Showing with 59 additions and 20 deletions.
  1. +41 −9 src/autolink.c
  2. +14 −7 src/autolink.h
  3. +3 −3 src/markdown.c
  4. +1 −1  sundown
View
50 src/autolink.c
@@ -15,6 +15,7 @@
*/
#include "buffer.h"
+#include "autolink.h"
#include <string.h>
#include <stdlib.h>
@@ -132,7 +133,7 @@ autolink_delim(uint8_t *data, size_t link_end, size_t offset, size_t size)
}
static size_t
-check_domain(uint8_t *data, size_t size)
+check_domain(uint8_t *data, size_t size, int allow_short)
{
size_t i, np = 0;
@@ -144,13 +145,27 @@ check_domain(uint8_t *data, size_t size)
else if (!isalnum(data[i]) && data[i] != '-') break;
}
- /* a valid domain needs to have at least a dot.
- * that's as far as we get */
- return np ? i : 0;
+ if (allow_short) {
+ /* We don't need a valid domain in the strict sense (with
+ * least one dot; so just make sure it's composed of valid
+ * domain characters and return the length of the the valid
+ * sequence. */
+ return i;
+ } else {
+ /* a valid domain needs to have at least a dot.
+ * that's as far as we get */
+ return np ? i : 0;
+ }
}
size_t
-sd_autolink__www(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size)
+sd_autolink__www(
+ size_t *rewind_p,
+ struct buf *link,
+ uint8_t *data,
+ size_t offset,
+ size_t size,
+ unsigned int flags)
{
size_t link_end;
@@ -160,7 +175,7 @@ sd_autolink__www(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offse
if (size < 4 || memcmp(data, "www.", strlen("www.")) != 0)
return 0;
- link_end = check_domain(data, size);
+ link_end = check_domain(data, size, 0);
if (link_end == 0)
return 0;
@@ -180,7 +195,13 @@ sd_autolink__www(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offse
}
size_t
-sd_autolink__email(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size)
+sd_autolink__email(
+ size_t *rewind_p,
+ struct buf *link,
+ uint8_t *data,
+ size_t offset,
+ size_t size,
+ unsigned int flags)
{
size_t link_end, rewind;
int nb = 0, np = 0;
@@ -229,7 +250,13 @@ sd_autolink__email(size_t *rewind_p, struct buf *link, uint8_t *data, size_t off
}
size_t
-sd_autolink__url(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size)
+sd_autolink__url(
+ size_t *rewind_p,
+ struct buf *link,
+ uint8_t *data,
+ size_t offset,
+ size_t size,
+ unsigned int flags)
{
size_t link_end, rewind = 0, domain_len;
@@ -241,9 +268,14 @@ sd_autolink__url(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offse
if (!sd_autolink_issafe(data - rewind, size + rewind))
return 0;
+
link_end = strlen("://");
- domain_len = check_domain(data + link_end, size - link_end);
+ domain_len = check_domain(
+ data + link_end,
+ size - link_end,
+ flags & SD_AUTOLINK_SHORT_DOMAINS);
+
if (domain_len == 0)
return 0;
View
21 src/autolink.h
@@ -23,17 +23,24 @@
extern "C" {
#endif
-extern int
+enum {
+ SD_AUTOLINK_SHORT_DOMAINS = (1 << 0),
+};
+
+int
sd_autolink_issafe(const uint8_t *link, size_t link_len);
-extern size_t
-sd_autolink__www(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size);
+size_t
+sd_autolink__www(size_t *rewind_p, struct buf *link,
+ uint8_t *data, size_t offset, size_t size, unsigned int flags);
-extern size_t
-sd_autolink__email(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size);
+size_t
+sd_autolink__email(size_t *rewind_p, struct buf *link,
+ uint8_t *data, size_t offset, size_t size, unsigned int flags);
-extern size_t
-sd_autolink__url(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size);
+size_t
+sd_autolink__url(size_t *rewind_p, struct buf *link,
+ uint8_t *data, size_t offset, size_t size, unsigned int flags);
#ifdef __cplusplus
}
View
6 src/markdown.c
@@ -771,7 +771,7 @@ char_autolink_www(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_
link = rndr_newbuf(rndr, BUFFER_SPAN);
- if ((link_len = sd_autolink__www(&rewind, link, data, offset, size)) > 0) {
+ if ((link_len = sd_autolink__www(&rewind, link, data, offset, size, 0)) > 0) {
link_url = rndr_newbuf(rndr, BUFFER_SPAN);
BUFPUTSL(link_url, "http://");
bufput(link_url, link->data, link->size);
@@ -803,7 +803,7 @@ char_autolink_email(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, siz
link = rndr_newbuf(rndr, BUFFER_SPAN);
- if ((link_len = sd_autolink__email(&rewind, link, data, offset, size)) > 0) {
+ if ((link_len = sd_autolink__email(&rewind, link, data, offset, size, 0)) > 0) {
ob->size -= rewind;
rndr->cb.autolink(ob, link, MKDA_EMAIL, rndr->opaque);
}
@@ -823,7 +823,7 @@ char_autolink_url(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_
link = rndr_newbuf(rndr, BUFFER_SPAN);
- if ((link_len = sd_autolink__url(&rewind, link, data, offset, size)) > 0) {
+ if ((link_len = sd_autolink__url(&rewind, link, data, offset, size, 0)) > 0) {
ob->size -= rewind;
rndr->cb.autolink(ob, link, MKDA_NORMAL, rndr->opaque);
}
2  sundown
@@ -1 +1 @@
-Subproject commit c744346e507e7f905d4b401de78db4404068a43c
+Subproject commit b6b58da3ffd43bc730174b49f0bb0a5ca3d969a5
Please sign in to comment.
Something went wrong with that request. Please try again.