Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
46ada388
Commit
46ada388
authored
9 years ago
by
Pavel Rojtberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix wrong parsing of values containing '='
fixes #5074
parent
1dd7f546
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
16 deletions
+27
-16
command_line_parser.cpp
modules/core/src/command_line_parser.cpp
+12
-16
test_utils.cpp
modules/core/test/test_utils.cpp
+15
-0
No files found.
modules/core/src/command_line_parser.cpp
View file @
46ada388
...
...
@@ -234,25 +234,21 @@ CommandLineParser::CommandLineParser(int argc, const char* const argv[], const S
jj
=
0
;
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
String
s
=
String
(
argv
[
i
]);
String
s
(
argv
[
i
]);
bool
hasSingleDash
=
s
.
length
()
>
1
&&
s
[
0
]
==
'-'
;
if
(
s
.
find
(
'='
)
!=
String
::
npos
&&
s
.
find
(
'='
)
<
s
.
length
()
)
if
(
hasSingleDash
)
{
std
::
vector
<
String
>
k_v
=
impl
->
split_string
(
s
,
'='
,
true
);
for
(
int
h
=
0
;
h
<
2
;
h
++
)
{
if
(
k_v
[
0
][
0
]
==
'-'
)
k_v
[
0
]
=
k_v
[
0
].
substr
(
1
,
k_v
[
0
].
length
()
-
1
);
}
impl
->
apply_params
(
k_v
[
0
],
k_v
[
1
]);
}
else
if
(
s
.
length
()
>
2
&&
s
[
0
]
==
'-'
&&
s
[
1
]
==
'-'
)
{
impl
->
apply_params
(
s
.
substr
(
2
),
"true"
);
bool
hasDoubleDash
=
s
.
length
()
>
2
&&
s
[
1
]
==
'-'
;
String
key
=
s
.
substr
(
hasDoubleDash
?
2
:
1
);
String
value
=
"true"
;
size_t
equalsPos
=
key
.
find
(
'='
);
if
(
equalsPos
!=
String
::
npos
)
{
value
=
key
.
substr
(
equalsPos
+
1
);
key
=
key
.
substr
(
0
,
equalsPos
);
}
else
if
(
s
.
length
()
>
1
&&
s
[
0
]
==
'-'
)
{
impl
->
apply_params
(
s
.
substr
(
1
),
"true"
);
impl
->
apply_params
(
key
,
value
);
}
else
{
...
...
This diff is collapsed.
Click to expand it.
modules/core/test/test_utils.cpp
View file @
46ada388
...
...
@@ -203,4 +203,19 @@ TEST(CommandLineParser, testEmptyStringValue)
EXPECT_FALSE
(
parser
.
check
());
}
TEST
(
CommandLineParser
,
positional_regression_5074_equal_sign
)
{
static
const
char
*
const
keys3
=
"{ @eq0 | | }"
"{ eq1 | | }"
;
const
char
*
argv
[]
=
{
"<bin>"
,
"1=0"
,
"--eq1=1=0"
};
const
int
argc
=
3
;
cv
::
CommandLineParser
parser
(
argc
,
argv
,
keys3
);
EXPECT_EQ
(
"1=0"
,
parser
.
get
<
String
>
(
"@eq0"
));
EXPECT_EQ
(
"1=0"
,
parser
.
get
<
String
>
(
0
));
EXPECT_EQ
(
"1=0"
,
parser
.
get
<
String
>
(
"eq1"
));
EXPECT_TRUE
(
parser
.
check
());
}
}
// namespace
This diff is collapsed.
Click to expand it.
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