Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
a1f0135d
Unverified
Commit
a1f0135d
authored
Oct 04, 2020
by
Edward Thomson
Committed by
GitHub
Oct 04, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5626 from csware/parse_bool
boolean config parsing fails in some cases with mapped values
parents
36dc681e
c464f123
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
6 deletions
+78
-6
src/config.c
+2
-6
tests/config/read.c
+76
-0
No files found.
src/config.c
View file @
a1f0135d
...
...
@@ -1227,9 +1227,6 @@ int git_config_lookup_map_value(
{
size_t
i
;
if
(
!
value
)
goto
fail_parse
;
for
(
i
=
0
;
i
<
map_n
;
++
i
)
{
const
git_configmap
*
m
=
maps
+
i
;
...
...
@@ -1238,7 +1235,7 @@ int git_config_lookup_map_value(
case
GIT_CONFIGMAP_TRUE
:
{
int
bool_val
;
if
(
git__parse_bool
(
&
bool_val
,
value
)
==
0
&&
if
(
git_
config
_parse_bool
(
&
bool_val
,
value
)
==
0
&&
bool_val
==
(
int
)
m
->
type
)
{
*
out
=
m
->
map_value
;
return
0
;
...
...
@@ -1252,7 +1249,7 @@ int git_config_lookup_map_value(
break
;
case
GIT_CONFIGMAP_STRING
:
if
(
strcasecmp
(
value
,
m
->
str_match
)
==
0
)
{
if
(
value
&&
strcasecmp
(
value
,
m
->
str_match
)
==
0
)
{
*
out
=
m
->
map_value
;
return
0
;
}
...
...
@@ -1260,7 +1257,6 @@ int git_config_lookup_map_value(
}
}
fail_parse:
git_error_set
(
GIT_ERROR_CONFIG
,
"failed to map '%s'"
,
value
);
return
-
1
;
}
...
...
tests/config/read.c
View file @
a1f0135d
...
...
@@ -928,3 +928,79 @@ void test_config_read__nosection(void)
git_buf_dispose
(
&
buf
);
git_config_free
(
cfg
);
}
enum
{
MAP_TRUE
=
0
,
MAP_FALSE
=
1
,
MAP_ALWAYS
=
2
};
static
git_configmap
_test_map1
[]
=
{
{
GIT_CONFIGMAP_STRING
,
"always"
,
MAP_ALWAYS
},
{
GIT_CONFIGMAP_FALSE
,
NULL
,
MAP_FALSE
},
{
GIT_CONFIGMAP_TRUE
,
NULL
,
MAP_TRUE
},
};
static
git_configmap
_test_map2
[]
=
{
{
GIT_CONFIGMAP_INT32
,
NULL
,
0
},
};
void
test_config_read__get_mapped
(
void
)
{
git_config
*
cfg
;
int
val
;
int
known_good
;
cl_set_cleanup
(
&
clean_test_config
,
NULL
);
cl_git_mkfile
(
"./testconfig"
,
"[header]
\n
"
" key1 = 1
\n
"
" key2 = true
\n
"
" key3
\n
"
" key4 = always
\n
"
" key5 = false
\n
"
" key6 = 0
\n
"
" key7 = never
\n
"
" key8 = On
\n
"
" key9 = off
\n
"
);
cl_git_pass
(
git_config_open_ondisk
(
&
cfg
,
"./testconfig"
));
// check parsing bool and string
cl_git_pass
(
git_config_get_mapped
(
&
val
,
cfg
,
"header.key1"
,
_test_map1
,
ARRAY_SIZE
(
_test_map1
)));
cl_assert_equal_i
(
val
,
MAP_TRUE
);
cl_git_pass
(
git_config_get_mapped
(
&
val
,
cfg
,
"header.key2"
,
_test_map1
,
ARRAY_SIZE
(
_test_map1
)));
cl_assert_equal_i
(
val
,
MAP_TRUE
);
cl_git_pass
(
git_config_get_mapped
(
&
val
,
cfg
,
"header.key3"
,
_test_map1
,
ARRAY_SIZE
(
_test_map1
)));
cl_assert_equal_i
(
val
,
MAP_TRUE
);
cl_git_pass
(
git_config_get_mapped
(
&
val
,
cfg
,
"header.key8"
,
_test_map1
,
ARRAY_SIZE
(
_test_map1
)));
cl_assert_equal_i
(
val
,
MAP_TRUE
);
cl_git_pass
(
git_config_get_mapped
(
&
val
,
cfg
,
"header.key4"
,
_test_map1
,
ARRAY_SIZE
(
_test_map1
)));
cl_assert_equal_i
(
val
,
MAP_ALWAYS
);
cl_git_pass
(
git_config_get_mapped
(
&
val
,
cfg
,
"header.key5"
,
_test_map1
,
ARRAY_SIZE
(
_test_map1
)));
cl_assert_equal_i
(
val
,
MAP_FALSE
);
cl_git_pass
(
git_config_get_mapped
(
&
val
,
cfg
,
"header.key6"
,
_test_map1
,
ARRAY_SIZE
(
_test_map1
)));
cl_assert_equal_i
(
val
,
MAP_FALSE
);
cl_git_pass
(
git_config_get_mapped
(
&
val
,
cfg
,
"header.key9"
,
_test_map1
,
ARRAY_SIZE
(
_test_map1
)));
cl_assert_equal_i
(
val
,
MAP_FALSE
);
cl_git_fail
(
git_config_get_mapped
(
&
val
,
cfg
,
"header.key7"
,
_test_map1
,
ARRAY_SIZE
(
_test_map1
)));
// check parsing int values
cl_git_pass
(
git_config_get_mapped
(
&
val
,
cfg
,
"header.key1"
,
_test_map2
,
ARRAY_SIZE
(
_test_map2
)));
cl_git_pass
(
git_config_get_int32
(
&
known_good
,
cfg
,
"header.key1"
));
cl_assert_equal_i
(
val
,
known_good
);
cl_git_pass
(
git_config_get_mapped
(
&
val
,
cfg
,
"header.key6"
,
_test_map2
,
ARRAY_SIZE
(
_test_map2
)));
cl_git_pass
(
git_config_get_int32
(
&
known_good
,
cfg
,
"header.key6"
));
cl_assert_equal_i
(
val
,
known_good
);
cl_git_fail
(
git_config_get_mapped
(
&
val
,
cfg
,
"header.key2"
,
_test_map2
,
ARRAY_SIZE
(
_test_map2
)));
cl_git_fail
(
git_config_get_mapped
(
&
val
,
cfg
,
"header.key3"
,
_test_map2
,
ARRAY_SIZE
(
_test_map2
)));
cl_git_fail
(
git_config_get_mapped
(
&
val
,
cfg
,
"header.key4"
,
_test_map2
,
ARRAY_SIZE
(
_test_map2
)));
cl_git_fail
(
git_config_get_mapped
(
&
val
,
cfg
,
"header.key5"
,
_test_map2
,
ARRAY_SIZE
(
_test_map2
)));
cl_git_fail
(
git_config_get_mapped
(
&
val
,
cfg
,
"header.key7"
,
_test_map2
,
ARRAY_SIZE
(
_test_map2
)));
cl_git_fail
(
git_config_get_mapped
(
&
val
,
cfg
,
"header.key8"
,
_test_map2
,
ARRAY_SIZE
(
_test_map2
)));
cl_git_fail
(
git_config_get_mapped
(
&
val
,
cfg
,
"header.key9"
,
_test_map2
,
ARRAY_SIZE
(
_test_map2
)));
git_config_free
(
cfg
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment