Skip to content

Commit 5c68acc

Browse files
mcfadden8adammoody
authored andcommitted
Treat '=' character as legal value in SCR_Config
Previously, the parser in SCR_Config was treating '=' as an invalid character within a value for a given token. This caused calling applications to fail when they passed in directory path names that contained an '=' character. This failure behavior is inconsistent because when the application uses environment variables instead of SCR_Config, this particular character is allowed. The fix was to remove the check when the parser is either in 'before_value' or 'in_value' state. Add tests for SCR_Config with '=' character Update SCR_Config docs describing '=' char as being valid
1 parent 6ce12d6 commit 5c68acc

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

doc/rst/users/api.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ and a multi-item form that consists of a parent key/value pair and set of child
122122

123123
To set a simple parameter,
124124
one specifies a parameter name and its value in the form of a :code:`key=value` string as the :code:`config` argument.
125-
For example, passing the string :code:`SCR_FLUSH=10` sets :code:`SCR_FLUSH` to the value of 10.
125+
For example, passing the string :code:`SCR_FLUSH=10` sets :code:`SCR_FLUSH` to the value of 10. The `=` character
126+
is allowed as part of the value if the value is a string. For example, passing the string
127+
:code:`SCR_PREFIX="/my/dir/with/=/sign"` sets :code:`SCR_PREFIX` to the value of "/my/dir/with/=/sign".
128+
126129
If one sets the same parameter with multiple calls to :code:`SCR_Config`,
127130
SCR applies the most recent value.
128131
When setting a parameter, for C applications, :code:`SCR_Config` always returns :code:`NULL`.

examples/test_config.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,16 @@ int main (int argc, char* argv[])
279279
SCR_Config("DEBUG=1");
280280
tests_passed &= test_cfg("DEBUG", "1", __LINE__);
281281

282+
/* test setting SCR_CACHE_BASE from with various names */
283+
tests_passed &= test_cfg("SCR_CACHE_BASE=/dev/shm/boring_name", NULL, __LINE__);
284+
tests_passed &= test_cfg("SCR_CACHE_BASE", "/dev/shm/boring_name", __LINE__);
285+
286+
tests_passed &= test_cfg("SCR_CACHE_BASE==/dev/shm/name_contains_preceding_=", NULL, __LINE__);
287+
tests_passed &= test_cfg("SCR_CACHE_BASE", "=/dev/shm/name_contains_preceding_=", __LINE__);
288+
289+
tests_passed &= test_cfg("SCR_CACHE_BASE= =/dev/shm/==name_contains_=_signs_everywhere", NULL, __LINE__);
290+
tests_passed &= test_cfg("SCR_CACHE_BASE", "=/dev/shm/==name_contains_=_signs_everywhere", __LINE__);
291+
282292
SCR_Config("SCR_COPY_TYPE=RS");
283293
if (SCR_Init() == SCR_SUCCESS) {
284294

src/scr.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2788,10 +2788,6 @@ const char* SCR_Config(const char* config_string)
27882788
state = done;
27892789
} else if (*conf == ' ') {
27902790
state = before_value;
2791-
} else if (*conf == '=') {
2792-
scr_abort(-1, "Invalid configuration string '%s' @ %s:%d",
2793-
config_string, __FILE__, __LINE__
2794-
);
27952791
} else {
27962792
value = conf;
27972793
if (toplevel_value == NULL) {
@@ -2813,10 +2809,6 @@ const char* SCR_Config(const char* config_string)
28132809
} else if (*conf == ' ') {
28142810
*conf = '\0';
28152811
state = before_key;
2816-
} else if (*conf == '=') {
2817-
scr_abort(-1, "Invalid configuration string '%s' @ %s:%d",
2818-
config_string, __FILE__, __LINE__
2819-
);
28202812
} else {
28212813
state = in_value;
28222814
}

0 commit comments

Comments
 (0)