Skip to content

Commit fff5fef

Browse files
committed
Merge branch 'upstream-master'
2 parents 07fe00f + 0378b31 commit fff5fef

7 files changed

+164
-28
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set(PROJECT_NAME "cmark")
1818

1919
set(PROJECT_VERSION_MAJOR 0)
2020
set(PROJECT_VERSION_MINOR 28)
21-
set(PROJECT_VERSION_PATCH 0)
21+
set(PROJECT_VERSION_PATCH 3)
2222
set(PROJECT_VERSION_GFM 11)
2323
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.gfm.${PROJECT_VERSION_GFM} )
2424

api_test/main.c

+91
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,95 @@ static void test_pathological_regressions(test_batch_runner *runner) {
989989
}
990990
}
991991

992+
static void source_pos(test_batch_runner *runner) {
993+
static const char markdown[] =
994+
"# Hi *there*.\n"
995+
"\n"
996+
"Hello &ldquo; <http://www.google.com>\n"
997+
"there `hi` -- [okay](www.google.com (ok)).\n"
998+
"\n"
999+
"> 1. Okay.\n"
1000+
"> Sure.\n"
1001+
">\n"
1002+
"> 2. Yes, okay.\n"
1003+
"> ![ok](hi \"yes\")\n";
1004+
1005+
cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
1006+
char *xml = cmark_render_xml(doc, CMARK_OPT_DEFAULT | CMARK_OPT_SOURCEPOS);
1007+
STR_EQ(runner, xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1008+
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
1009+
"<document sourcepos=\"1:1-10:20\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
1010+
" <heading sourcepos=\"1:1-1:13\" level=\"1\">\n"
1011+
" <text sourcepos=\"1:3-1:5\">Hi </text>\n"
1012+
" <emph sourcepos=\"1:6-1:12\">\n"
1013+
" <text sourcepos=\"1:7-1:11\">there</text>\n"
1014+
" </emph>\n"
1015+
" <text sourcepos=\"1:13-1:13\">.</text>\n"
1016+
" </heading>\n"
1017+
" <paragraph sourcepos=\"3:1-4:42\">\n"
1018+
" <text sourcepos=\"3:1-3:14\">Hello “ </text>\n"
1019+
" <link sourcepos=\"3:15-3:37\" destination=\"http://www.google.com\" title=\"\">\n"
1020+
" <text sourcepos=\"3:16-3:36\">http://www.google.com</text>\n"
1021+
" </link>\n"
1022+
" <softbreak />\n"
1023+
" <text sourcepos=\"4:1-4:6\">there </text>\n"
1024+
" <code sourcepos=\"4:8-4:9\">hi</code>\n"
1025+
" <text sourcepos=\"4:11-4:14\"> -- </text>\n"
1026+
" <link sourcepos=\"4:15-4:41\" destination=\"www.google.com\" title=\"ok\">\n"
1027+
" <text sourcepos=\"4:16-4:19\">okay</text>\n"
1028+
" </link>\n"
1029+
" <text sourcepos=\"4:42-4:42\">.</text>\n"
1030+
" </paragraph>\n"
1031+
" <block_quote sourcepos=\"6:1-10:20\">\n"
1032+
" <list sourcepos=\"6:3-10:20\" type=\"ordered\" start=\"1\" delim=\"period\" tight=\"false\">\n"
1033+
" <item sourcepos=\"6:3-8:1\">\n"
1034+
" <paragraph sourcepos=\"6:6-7:10\">\n"
1035+
" <text sourcepos=\"6:6-6:10\">Okay.</text>\n"
1036+
" <softbreak />\n"
1037+
" <text sourcepos=\"7:6-7:10\">Sure.</text>\n"
1038+
" </paragraph>\n"
1039+
" </item>\n"
1040+
" <item sourcepos=\"9:3-10:20\">\n"
1041+
" <paragraph sourcepos=\"9:6-10:20\">\n"
1042+
" <text sourcepos=\"9:6-9:15\">Yes, okay.</text>\n"
1043+
" <softbreak />\n"
1044+
" <image sourcepos=\"10:6-10:20\" destination=\"hi\" title=\"yes\">\n"
1045+
" <text sourcepos=\"10:8-10:9\">ok</text>\n"
1046+
" </image>\n"
1047+
" </paragraph>\n"
1048+
" </item>\n"
1049+
" </list>\n"
1050+
" </block_quote>\n"
1051+
"</document>\n",
1052+
"sourcepos are as expected");
1053+
free(xml);
1054+
cmark_node_free(doc);
1055+
}
1056+
1057+
static void ref_source_pos(test_batch_runner *runner) {
1058+
static const char markdown[] =
1059+
"Let's try [reference] links.\n"
1060+
"\n"
1061+
"[reference]: https://github.com (GitHub)\n";
1062+
1063+
cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
1064+
char *xml = cmark_render_xml(doc, CMARK_OPT_DEFAULT | CMARK_OPT_SOURCEPOS);
1065+
STR_EQ(runner, xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1066+
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
1067+
"<document sourcepos=\"1:1-3:40\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
1068+
" <paragraph sourcepos=\"1:1-1:28\">\n"
1069+
" <text sourcepos=\"1:1-1:10\">Let's try </text>\n"
1070+
" <link sourcepos=\"1:11-1:21\" destination=\"https://github.com\" title=\"GitHub\">\n"
1071+
" <text sourcepos=\"1:12-1:20\">reference</text>\n"
1072+
" </link>\n"
1073+
" <text sourcepos=\"1:22-1:28\"> links.</text>\n"
1074+
" </paragraph>\n"
1075+
"</document>\n",
1076+
"sourcepos are as expected");
1077+
free(xml);
1078+
cmark_node_free(doc);
1079+
}
1080+
9921081
int main() {
9931082
int retval;
9941083
test_batch_runner *runner = test_batch_runner_new();
@@ -1016,6 +1105,8 @@ int main() {
10161105
test_safe(runner);
10171106
test_feed_across_line_ending(runner);
10181107
test_pathological_regressions(runner);
1108+
source_pos(runner);
1109+
ref_source_pos(runner);
10191110

10201111
test_print_summary(runner);
10211112
retval = test_ok(runner) ? 0 : 1;

changelog.txt

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
[0.28.3]
2+
3+
* Include GNUInstallDirs in src/CMakeLists.txt (Nick Wellnhofer, #240).
4+
This fixes build problems on some cmake versions (#241).
5+
6+
[0.28.2]
7+
8+
* Fixed regression in install dest for static library (#238).
9+
Due to a mistake, 0.28.1 installed libcmark.a into include/.
10+
11+
[0.28.1]
12+
13+
* `--smart`: open quote can never occur right after `]` or `)` (#227).
14+
* Fix quadratic behavior in `finalize` (Vicent Marti).
15+
* Don't use `CMAKE_INSTALL_LIBDIR` to create `libcmark.pc` (#236).
16+
This wasn't getting set in processing `libcmark.pc.in`, and we
17+
were getting the wrong entry in `libcmark.pc`.
18+
The new approach sets an internal `libdir` variable to
19+
`lib${LIB_SUFFIX}`. This variable is used both to set the
20+
install destination and in the libcmark.pc.in template.
21+
* Update README.md, replace `make astyle` with `make format`
22+
(Nguyễn Thái Ngọc Duy).
23+
124
[0.28.0.gfm.11]
225

326
* Do not output empty `<tbody>` in table extension.
@@ -32,7 +55,7 @@
3255
* Add `core_extensions_ensure_registered`.
3356
* Add sourcepos information for inlines.
3457

35-
[0.28]
58+
[0.28.0]
3659

3760
* Update spec.
3861
* Use unsigned integer when shifting (Phil Turnbull).

src/CMakeLists.txt

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ if(${CMAKE_VERSION} VERSION_GREATER "3.3")
22
cmake_policy(SET CMP0063 NEW)
33
endif()
44

5+
include(GNUInstallDirs)
6+
57
set(LIBRARY "libcmark-gfm")
68
set(STATICLIBRARY "libcmark-gfm_static")
79
set(HEADERS
@@ -139,19 +141,21 @@ endif(MSVC)
139141

140142
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
141143

144+
set(libdir lib${LIB_SUFFIX})
145+
142146
include (InstallRequiredSystemLibraries)
143147
install(TARGETS ${PROGRAM} ${CMARK_INSTALL}
144148
EXPORT cmark-gfm
145149
RUNTIME DESTINATION bin
146-
LIBRARY DESTINATION lib${LIB_SUFFIX}
147-
ARCHIVE DESTINATION lib${LIB_SUFFIX}
150+
LIBRARY DESTINATION ${libdir}
151+
ARCHIVE DESTINATION ${libdir}
148152
)
149153

150154
if(CMARK_SHARED OR CMARK_STATIC)
151155
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libcmark-gfm.pc.in
152156
${CMAKE_CURRENT_BINARY_DIR}/libcmark-gfm.pc @ONLY)
153157
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcmark-gfm.pc
154-
DESTINATION lib${LIB_SUFFIX}/pkgconfig)
158+
DESTINATION ${libdir}/pkgconfig)
155159

156160
install(FILES
157161
cmark.h
@@ -161,7 +165,7 @@ if(CMARK_SHARED OR CMARK_STATIC)
161165
DESTINATION include
162166
)
163167

164-
install(EXPORT cmark-gfm DESTINATION lib${LIB_SUFFIX}/cmake-gfm)
168+
install(EXPORT cmark-gfm DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmark-gfm)
165169
endif()
166170

167171
# Feature tests

src/inlines.c

+18-18
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ cmark_chunk cmark_clean_url(cmark_mem *mem, cmark_chunk *url) {
793793
return result;
794794
}
795795

796-
houdini_unescape_html_f(&buf, url->data, url->len);
796+
houdini_unescape_html_f(&buf, url->data, url->len);
797797

798798
cmark_strbuf_unescape(&buf);
799799
return cmark_chunk_buf_detach(&buf);
@@ -925,26 +925,26 @@ static bufsize_t manual_scan_link_url_2(cmark_chunk *input, bufsize_t offset,
925925
bufsize_t i = offset;
926926
size_t nb_p = 0;
927927

928-
while (i < input->len) {
929-
if (input->data[i] == '\\' &&
930-
i + 1 < input-> len &&
931-
cmark_ispunct(input->data[i+1]))
932-
i += 2;
933-
else if (input->data[i] == '(') {
934-
++nb_p;
935-
++i;
928+
while (i < input->len) {
929+
if (input->data[i] == '\\' &&
930+
i + 1 < input-> len &&
931+
cmark_ispunct(input->data[i+1]))
932+
i += 2;
933+
else if (input->data[i] == '(') {
934+
++nb_p;
935+
++i;
936936
if (nb_p > 32)
937937
return -1;
938-
} else if (input->data[i] == ')') {
939-
if (nb_p == 0)
940-
break;
941-
--nb_p;
942-
++i;
943-
} else if (cmark_isspace(input->data[i]))
938+
} else if (input->data[i] == ')') {
939+
if (nb_p == 0)
944940
break;
945-
else
946-
++i;
947-
}
941+
--nb_p;
942+
++i;
943+
} else if (cmark_isspace(input->data[i]))
944+
break;
945+
else
946+
++i;
947+
}
948948

949949
if (i >= input->len)
950950
return -1;

src/libcmark-gfm.pc.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
prefix=@CMAKE_INSTALL_PREFIX@
22
exec_prefix=@CMAKE_INSTALL_PREFIX@
3-
libdir=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@
3+
libdir=@CMAKE_INSTALL_PREFIX@/@libdir@
44
includedir=@CMAKE_INSTALL_PREFIX@/include
55

66
Name: libcmark-gfm

test/pathological_tests.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def badhash(ref):
3131

3232
return document, re.compile("(<p>\[%s\]</p>\n){%d}" % (bad_key, COUNT-1))
3333

34+
allowed_failures = {"many references": True}
35+
3436
# list of pairs consisting of input and a regex that must match the output.
3537
pathological = {
3638
# note - some pythons have limit of 65535 for {num-matches} in re.
@@ -73,12 +75,22 @@ def badhash(ref):
7375
"backticks":
7476
("".join(map(lambda x: ("e" + "`" * x), range(1,10000))),
7577
re.compile("^<p>[e`]*</p>\n$")),
78+
"unclosed links A":
79+
("[a](<b" * 50000,
80+
re.compile("(\[a\]\(&lt;b){50000}")),
81+
"unclosed links B":
82+
("[a](b" * 50000,
83+
re.compile("(\[a\]\(b){50000}")),
84+
"many references":
85+
("".join(map(lambda x: ("[" + str(x) + "]: u\n"), range(1,50000 * 16))) + "[0] " * 50000,
86+
re.compile("(\[0\] ){49999}")),
7687
"reference collisions": hash_collisions()
7788
}
7889

7990
whitespace_re = re.compile('/s+/')
8091
passed = 0
8192
errored = 0
93+
ignored = 0
8294
TIMEOUT = 5
8395

8496
def run_test(inp, regex):
@@ -117,11 +129,17 @@ def run_test(inp, regex):
117129
p.terminate()
118130
p.join()
119131
print('[TIMED OUT]')
120-
errored += 1
132+
if allowed_failures[description]:
133+
ignored += 1
134+
else:
135+
errored += 1
121136
elif p.exitcode != 0:
122-
errored += 1
137+
if allowed_failures[description]:
138+
ignored += 1
139+
else:
140+
errored += 1
123141
else:
124142
passed += 1
125143

126-
print("%d passed, %d errored" % (passed, errored))
144+
print("%d passed, %d errored, %d ignored" % (passed, errored, ignored))
127145
exit(errored)

0 commit comments

Comments
 (0)