Browse Source

[uri] Support URIs containing only scheme and path components

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 years ago
parent
commit
17c1488a44
2 changed files with 33 additions and 3 deletions
  1. 2
    3
      src/core/uri.c
  2. 31
    0
      src/tests/uri_test.c

+ 2
- 3
src/core/uri.c View File

@@ -456,7 +456,6 @@ unsigned int uri_port ( const struct uri *uri, unsigned int default_port ) {
456 456
  */
457 457
 size_t format_uri ( const struct uri *uri, char *buf, size_t len ) {
458 458
 	static const char prefixes[URI_FIELDS] = {
459
-		[URI_OPAQUE] = ':',
460 459
 		[URI_PASSWORD] = ':',
461 460
 		[URI_PORT] = ':',
462 461
 		[URI_QUERY] = '?',
@@ -495,9 +494,9 @@ size_t format_uri ( const struct uri *uri, char *buf, size_t len ) {
495 494
 					    ( buf + used ), ( len - used ) );
496 495
 
497 496
 		/* Suffix this field, if applicable */
498
-		if ( ( field == URI_SCHEME ) && ( ! uri->opaque ) ) {
497
+		if ( field == URI_SCHEME ) {
499 498
 			used += ssnprintf ( ( buf + used ), ( len - used ),
500
-					    "://" );
499
+					    ":%s", ( uri->host ? "//" : "" ) );
501 500
 		}
502 501
 	}
503 502
 

+ 31
- 0
src/tests/uri_test.c View File

@@ -610,6 +610,34 @@ static struct uri_test uri_iscsi = {
610 610
 	},
611 611
 };
612 612
 
613
+/** File URI with relative (opaque) path */
614
+static struct uri_test uri_file_relative = {
615
+	"file:script.ipxe",
616
+	{
617
+		.scheme = "file",
618
+		.opaque = "script.ipxe",
619
+	},
620
+};
621
+
622
+/** File URI with absolute path */
623
+static struct uri_test uri_file_absolute = {
624
+	"file:/boot/script.ipxe",
625
+	{
626
+		.scheme = "file",
627
+		.path = "/boot/script.ipxe",
628
+	},
629
+};
630
+
631
+/** File URI with volume name */
632
+static struct uri_test uri_file_volume = {
633
+	"file://hpilo/boot/script.ipxe",
634
+	{
635
+		.scheme = "file",
636
+		.host = "hpilo",
637
+		.path = "/boot/script.ipxe",
638
+	},
639
+};
640
+
613 641
 /** URI with port number */
614 642
 static struct uri_port_test uri_explicit_port = {
615 643
 	"http://192.168.0.1:8080/boot.php",
@@ -899,6 +927,9 @@ static void uri_test_exec ( void ) {
899 927
 	uri_parse_format_dup_ok ( &uri_ipv6_local );
900 928
 	uri_parse_ok ( &uri_ipv6_local_non_conforming ); /* Parse only */
901 929
 	uri_parse_format_dup_ok ( &uri_iscsi );
930
+	uri_parse_format_dup_ok ( &uri_file_relative );
931
+	uri_parse_format_dup_ok ( &uri_file_absolute );
932
+	uri_parse_format_dup_ok ( &uri_file_volume );
902 933
 
903 934
 	/** URI port number tests */
904 935
 	uri_port_ok ( &uri_explicit_port );

Loading…
Cancel
Save