Skip to content

Commit ffaa80e

Browse files
committed
uri fails to parse compact ipv6 representation
1. Hangs on ::1. The rule that matches anything before '::' should match 0 or 1 occurance. 2. qi::repeat(min, max) is greedy in nature. Workaround to use qi::repeat(n) multiple times with varying n.
1 parent c79b637 commit ffaa80e

File tree

2 files changed

+149
-16
lines changed

2 files changed

+149
-16
lines changed

include/network/uri/uri.ipp

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,36 @@ struct uri_grammar : qi::grammar<
108108
;
109109

110110
ipv6address %= qi::raw[
111-
qi::repeat(6)[h16 >> ':'] >> ls32
112-
| "::" >> qi::repeat(5)[h16 >> ':'] >> ls32
113-
| qi::raw[ h16] >> "::" >> qi::repeat(4)[h16 >> ':'] >> ls32
114-
| qi::raw[ +(*(h16 >> ':')) >> h16] >> "::" >> qi::repeat(3)[h16 >> ':'] >> ls32
115-
| qi::raw[qi::repeat(2)[*(h16 >> ':')] >> h16] >> "::" >> qi::repeat(2)[h16 >> ':'] >> ls32
116-
| qi::raw[qi::repeat(3)[*(h16 >> ':')] >> h16] >> "::" >> h16 >> ':' >> ls32
117-
| qi::raw[qi::repeat(4)[*(h16 >> ':')] >> h16] >> "::" >> ls32
118-
| qi::raw[qi::repeat(5)[*(h16 >> ':')] >> h16] >> "::" >> h16
119-
| qi::raw[qi::repeat(6)[*(h16 >> ':')] >> h16] >> "::"
111+
qi::repeat(6)[h16 >> ':'] >> ls32
112+
| "::" >> qi::repeat(5)[h16 >> ':'] >> ls32
113+
| - qi::raw[ h16] >> "::" >> qi::repeat(4)[h16 >> ':'] >> ls32
114+
| - qi::raw[ h16] >> "::" >> qi::repeat(3)[h16 >> ':'] >> ls32
115+
| - qi::raw[ h16] >> "::" >> qi::repeat(2)[h16 >> ':'] >> ls32
116+
| - qi::raw[ h16] >> "::" >> h16 >> ':' >> ls32
117+
| - qi::raw[ h16] >> "::" >> ls32
118+
| - qi::raw[ h16] >> "::" >> h16
119+
| - qi::raw[ h16] >> "::"
120+
| - qi::raw[qi::repeat(1)[(h16 >> ':')] >> h16] >> "::" >> qi::repeat(3)[h16 >> ':'] >> ls32
121+
| - qi::raw[qi::repeat(1)[(h16 >> ':')] >> h16] >> "::" >> qi::repeat(2)[h16 >> ':'] >> ls32
122+
| - qi::raw[qi::repeat(1)[(h16 >> ':')] >> h16] >> "::" >> h16 >> ':' >> ls32
123+
| - qi::raw[qi::repeat(1)[(h16 >> ':')] >> h16] >> "::" >> ls32
124+
| - qi::raw[qi::repeat(1)[(h16 >> ':')] >> h16] >> "::" >> h16
125+
| - qi::raw[qi::repeat(1)[(h16 >> ':')] >> h16] >> "::"
126+
| - qi::raw[qi::repeat(2)[(h16 >> ':')] >> h16] >> "::" >> qi::repeat(2)[h16 >> ':'] >> ls32
127+
| - qi::raw[qi::repeat(2)[(h16 >> ':')] >> h16] >> "::" >> h16 >> ':' >> ls32
128+
| - qi::raw[qi::repeat(2)[(h16 >> ':')] >> h16] >> "::" >> ls32
129+
| - qi::raw[qi::repeat(2)[(h16 >> ':')] >> h16] >> "::" >> h16
130+
| - qi::raw[qi::repeat(2)[(h16 >> ':')] >> h16] >> "::"
131+
| - qi::raw[qi::repeat(3)[(h16 >> ':')] >> h16] >> "::" >> h16 >> ':' >> ls32
132+
| - qi::raw[qi::repeat(3)[(h16 >> ':')] >> h16] >> "::" >> ls32
133+
| - qi::raw[qi::repeat(3)[(h16 >> ':')] >> h16] >> "::" >> h16
134+
| - qi::raw[qi::repeat(3)[(h16 >> ':')] >> h16] >> "::"
135+
| - qi::raw[qi::repeat(4)[(h16 >> ':')] >> h16] >> "::" >> ls32
136+
| - qi::raw[qi::repeat(4)[(h16 >> ':')] >> h16] >> "::" >> h16
137+
| - qi::raw[qi::repeat(4)[(h16 >> ':')] >> h16] >> "::"
138+
| - qi::raw[qi::repeat(5)[(h16 >> ':')] >> h16] >> "::" >> h16
139+
| - qi::raw[qi::repeat(5)[(h16 >> ':')] >> h16] >> "::"
140+
| - qi::raw[qi::repeat(6)[(h16 >> ':')] >> h16] >> "::"
120141
];
121142

122143
// ls32 = ( h16 ":" h16 ) / IPv4address

libs/network/test/uri/uri_test.cpp

Lines changed: 119 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,125 @@ BOOST_AUTO_TEST_CASE(ipv6_address_test_2) {
273273
BOOST_CHECK_EQUAL(network::path(instance), "/");
274274
}
275275

276-
//BOOST_AUTO_TEST_CASE(ipv6_loopback_test) {
277-
// network::uri instance("http://[::1]/");
278-
// BOOST_REQUIRE(network::valid(instance));
279-
// BOOST_CHECK_EQUAL(network::scheme(instance), "http");
280-
// BOOST_CHECK_EQUAL(network::host(instance), "[::1]");
281-
// BOOST_CHECK_EQUAL(network::path(instance), "/");
282-
//}
276+
BOOST_AUTO_TEST_CASE(ipv6_address_test_3) {
277+
network::uri instance("http://[2001:db8:85a3:0:0:8a2e:370:7334]/");
278+
BOOST_REQUIRE(network::valid(instance));
279+
BOOST_CHECK_EQUAL(network::scheme(instance), "http");
280+
BOOST_CHECK_EQUAL(network::host(instance), "[2001:db8:85a3:0:0:8a2e:370:7334]");
281+
BOOST_CHECK_EQUAL(network::path(instance), "/");
282+
}
283+
284+
BOOST_AUTO_TEST_CASE(ipv6_address_test_4) {
285+
network::uri instance("http://[2001:db8:85a3::8a2e:370:7334]/");
286+
BOOST_REQUIRE(network::valid(instance));
287+
BOOST_CHECK_EQUAL(network::scheme(instance), "http");
288+
BOOST_CHECK_EQUAL(network::host(instance), "[2001:db8:85a3::8a2e:370:7334]");
289+
BOOST_CHECK_EQUAL(network::path(instance), "/");
290+
}
291+
292+
BOOST_AUTO_TEST_CASE(ipv6_address_test_5) {
293+
network::uri instance("http://[2001:0db8:0000:0000:0000:0000:1428:57ab]/");
294+
BOOST_REQUIRE(network::valid(instance));
295+
BOOST_CHECK_EQUAL(network::scheme(instance), "http");
296+
BOOST_CHECK_EQUAL(network::host(instance), "[2001:0db8:0000:0000:0000:0000:1428:57ab]");
297+
BOOST_CHECK_EQUAL(network::path(instance), "/");
298+
}
299+
300+
BOOST_AUTO_TEST_CASE(ipv6_address_test_6) {
301+
network::uri instance("http://[2001:0db8:0000:0000:0000::1428:57ab]/");
302+
BOOST_REQUIRE(network::valid(instance));
303+
BOOST_CHECK_EQUAL(network::scheme(instance), "http");
304+
BOOST_CHECK_EQUAL(network::host(instance), "[2001:0db8:0000:0000:0000::1428:57ab]");
305+
BOOST_CHECK_EQUAL(network::path(instance), "/");
306+
}
307+
308+
BOOST_AUTO_TEST_CASE(ipv6_address_test_7) {
309+
network::uri instance("http://[2001:0db8:0:0:0:0:1428:57ab]/");
310+
BOOST_REQUIRE(network::valid(instance));
311+
BOOST_CHECK_EQUAL(network::scheme(instance), "http");
312+
BOOST_CHECK_EQUAL(network::host(instance), "[2001:0db8:0:0:0:0:1428:57ab]");
313+
BOOST_CHECK_EQUAL(network::path(instance), "/");
314+
}
315+
316+
BOOST_AUTO_TEST_CASE(ipv6_address_test_8) {
317+
network::uri instance("http://[2001:0db8:0:0::1428:57ab]/");
318+
BOOST_REQUIRE(network::valid(instance));
319+
BOOST_CHECK_EQUAL(network::scheme(instance), "http");
320+
BOOST_CHECK_EQUAL(network::host(instance), "[2001:0db8:0:0::1428:57ab]");
321+
BOOST_CHECK_EQUAL(network::path(instance), "/");
322+
}
323+
324+
BOOST_AUTO_TEST_CASE(ipv6_address_test_9) {
325+
network::uri instance("http://[2001:0db8::1428:57ab]/");
326+
BOOST_REQUIRE(network::valid(instance));
327+
BOOST_CHECK_EQUAL(network::scheme(instance), "http");
328+
BOOST_CHECK_EQUAL(network::host(instance), "[2001:0db8::1428:57ab]");
329+
BOOST_CHECK_EQUAL(network::path(instance), "/");
330+
}
331+
332+
BOOST_AUTO_TEST_CASE(ipv6_address_test_10) {
333+
network::uri instance("http://[2001:db8::1428:57ab]/");
334+
BOOST_REQUIRE(network::valid(instance));
335+
BOOST_CHECK_EQUAL(network::scheme(instance), "http");
336+
BOOST_CHECK_EQUAL(network::host(instance), "[2001:db8::1428:57ab]");
337+
BOOST_CHECK_EQUAL(network::path(instance), "/");
338+
}
339+
340+
BOOST_AUTO_TEST_CASE(ipv6_address_test_11) {
341+
network::uri instance("http://[::ffff:0c22:384e]/");
342+
BOOST_REQUIRE(network::valid(instance));
343+
BOOST_CHECK_EQUAL(network::scheme(instance), "http");
344+
BOOST_CHECK_EQUAL(network::host(instance), "[::ffff:0c22:384e]");
345+
BOOST_CHECK_EQUAL(network::path(instance), "/");
346+
}
347+
348+
BOOST_AUTO_TEST_CASE(ipv6_address_test_12) {
349+
network::uri instance("http://[fe80::]/");
350+
BOOST_REQUIRE(network::valid(instance));
351+
BOOST_CHECK_EQUAL(network::scheme(instance), "http");
352+
BOOST_CHECK_EQUAL(network::host(instance), "[fe80::]");
353+
BOOST_CHECK_EQUAL(network::path(instance), "/");
354+
}
355+
356+
BOOST_AUTO_TEST_CASE(ipv6_address_test_13) {
357+
network::uri instance("http://[::ffff:c000:280]/");
358+
BOOST_REQUIRE(network::valid(instance));
359+
BOOST_CHECK_EQUAL(network::scheme(instance), "http");
360+
BOOST_CHECK_EQUAL(network::host(instance), "[::ffff:c000:280]");
361+
BOOST_CHECK_EQUAL(network::path(instance), "/");
362+
}
363+
364+
BOOST_AUTO_TEST_CASE(ipv6_loopback_test) {
365+
network::uri instance("http://[::1]/");
366+
BOOST_REQUIRE(network::valid(instance));
367+
BOOST_CHECK_EQUAL(network::scheme(instance), "http");
368+
BOOST_CHECK_EQUAL(network::host(instance), "[::1]");
369+
BOOST_CHECK_EQUAL(network::path(instance), "/");
370+
}
371+
372+
BOOST_AUTO_TEST_CASE(ipv6_loopback_test_1) {
373+
network::uri instance("http://[0000:0000:0000:0000:0000:0000:0000:0001]/");
374+
BOOST_REQUIRE(network::valid(instance));
375+
BOOST_CHECK_EQUAL(network::scheme(instance), "http");
376+
BOOST_CHECK_EQUAL(network::host(instance), "[0000:0000:0000:0000:0000:0000:0000:0001]");
377+
BOOST_CHECK_EQUAL(network::path(instance), "/");
378+
}
379+
380+
BOOST_AUTO_TEST_CASE(ipv6_v4inv6_test_1) {
381+
network::uri instance("http://[::ffff:12.34.56.78]/");
382+
BOOST_REQUIRE(network::valid(instance));
383+
BOOST_CHECK_EQUAL(network::scheme(instance), "http");
384+
BOOST_CHECK_EQUAL(network::host(instance), "[::ffff:12.34.56.78]");
385+
BOOST_CHECK_EQUAL(network::path(instance), "/");
386+
}
387+
388+
BOOST_AUTO_TEST_CASE(ipv6_v4inv6_test_2) {
389+
network::uri instance("http://[::ffff:192.0.2.128]/");
390+
BOOST_REQUIRE(network::valid(instance));
391+
BOOST_CHECK_EQUAL(network::scheme(instance), "http");
392+
BOOST_CHECK_EQUAL(network::host(instance), "[::ffff:192.0.2.128]");
393+
BOOST_CHECK_EQUAL(network::path(instance), "/");
394+
}
283395

284396
BOOST_AUTO_TEST_CASE(ftp_test) {
285397
network::uri instance("ftp://[email protected]/");

0 commit comments

Comments
 (0)