Skip to content

Commit 09b057c

Browse files
committed
[settings] Remove "uristring" setting type
Commit b5f5f73 ("[cmdline] Expand settings within each command-line token individually") effectively rendered the "uristring" setting type obsolete, since strings containing whitespace no longer break the command line parser. The concept of the "uristring" type is not well defined, since URI escaping rules depend on which portion of a URI is being escaped. Remove the "uristring" type, converting it into an alias for the "string" setting type so as to avoid breaking existing scripts. Signed-off-by: Michael Brown <mcb30@ipxe.org>
1 parent ced4f8d commit 09b057c

2 files changed

Lines changed: 5 additions & 62 deletions

File tree

src/core/settings.c

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,59 +1658,15 @@ const struct setting_type setting_type_string __setting_type = {
16581658
.format = format_string_setting,
16591659
};
16601660

1661-
/**
1662-
* Parse URI-encoded string setting value
1661+
/** A URI-encoded string setting type
16631662
*
1664-
* @v type Setting type
1665-
* @v value Formatted setting value
1666-
* @v buf Buffer to contain raw value
1667-
* @v len Length of buffer
1668-
* @ret len Length of raw value, or negative error
1663+
* This setting type is obsolete; the name ":uristring" is retained to
1664+
* avoid breaking existing scripts.
16691665
*/
1670-
static int parse_uristring_setting ( const struct setting_type *type __unused,
1671-
const char *value, void *buf, size_t len ){
1672-
char tmp[ len + 1 /* NUL */ ];
1673-
size_t raw_len;
1674-
1675-
/* Decode to temporary buffer (including NUL) */
1676-
raw_len = uri_decode ( value, tmp, sizeof ( tmp ) );
1677-
1678-
/* Copy to output buffer (excluding NUL) */
1679-
if ( len > raw_len )
1680-
len = raw_len;
1681-
memcpy ( buf, tmp, len );
1682-
1683-
return raw_len;
1684-
}
1685-
1686-
/**
1687-
* Format URI-encoded string setting value
1688-
*
1689-
* @v type Setting type
1690-
* @v raw Raw setting value
1691-
* @v raw_len Length of raw setting value
1692-
* @v buf Buffer to contain formatted value
1693-
* @v len Length of buffer
1694-
* @ret len Length of formatted value, or negative error
1695-
*/
1696-
static int format_uristring_setting ( const struct setting_type *type __unused,
1697-
const void *raw, size_t raw_len,
1698-
char *buf, size_t len ) {
1699-
char tmp[ raw_len + 1 /* NUL */ ];
1700-
1701-
/* Copy to temporary buffer and terminate */
1702-
memcpy ( tmp, raw, raw_len );
1703-
tmp[raw_len] = '\0';
1704-
1705-
/* Encode directly into output buffer */
1706-
return uri_encode ( tmp, buf, len, URI_FRAGMENT );
1707-
}
1708-
1709-
/** A URI-encoded string setting type */
17101666
const struct setting_type setting_type_uristring __setting_type = {
17111667
.name = "uristring",
1712-
.parse = parse_uristring_setting,
1713-
.format = format_uristring_setting,
1668+
.parse = parse_string_setting,
1669+
.format = format_string_setting,
17141670
};
17151671

17161672
/**

src/tests/settings_test.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,6 @@ static struct setting test_string_setting = {
162162
.type = &setting_type_string,
163163
};
164164

165-
/** Test URI-encoded string setting */
166-
static struct setting test_uristring_setting = {
167-
.name = "test_uristring",
168-
.type = &setting_type_uristring,
169-
};
170-
171165
/** Test IPv4 address setting type */
172166
static struct setting test_ipv4_setting = {
173167
.name = "test_ipv4",
@@ -261,13 +255,6 @@ static void settings_test_exec ( void ) {
261255
fetchf_ok ( &test_settings, &test_string_setting,
262256
RAW ( 'w', 'o', 'r', 'l', 'd' ), "world" );
263257

264-
/* "uristring" setting type */
265-
storef_ok ( &test_settings, &test_uristring_setting, "hello%20world",
266-
RAW ( 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l',
267-
'd' ) );
268-
fetchf_ok ( &test_settings, &test_uristring_setting,
269-
RAW ( 1, 2, 3, 4, 5 ), "%01%02%03%04%05" );
270-
271258
/* "ipv4" setting type */
272259
storef_ok ( &test_settings, &test_ipv4_setting, "192.168.0.1",
273260
RAW ( 192, 168, 0, 1 ) );

0 commit comments

Comments
 (0)