Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
b2da19b8
Unverified
Commit
b2da19b8
authored
Nov 11, 2019
by
Nikita Titov
Committed by
GitHub
Nov 11, 2019
Browse files
check feature names for special JSON chars (#2557)
parent
83ecb386
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
2 deletions
+24
-2
include/LightGBM/dataset.h
include/LightGBM/dataset.h
+5
-1
include/LightGBM/utils/common.h
include/LightGBM/utils/common.h
+18
-0
src/io/config.cpp
src/io/config.cpp
+1
-1
No files found.
include/LightGBM/dataset.h
View file @
b2da19b8
...
@@ -561,7 +561,11 @@ class Dataset {
...
@@ -561,7 +561,11 @@ class Dataset {
for
(
auto
&
feature_name
:
feature_names_
)
{
for
(
auto
&
feature_name
:
feature_names_
)
{
// check ascii
// check ascii
if
(
!
Common
::
CheckASCII
(
feature_name
))
{
if
(
!
Common
::
CheckASCII
(
feature_name
))
{
Log
::
Fatal
(
"Do not support non-ascii characters in feature name."
);
Log
::
Fatal
(
"Do not support non-ASCII characters in feature name."
);
}
// check json
if
(
!
Common
::
CheckAllowedJSON
(
feature_name
))
{
Log
::
Fatal
(
"Do not support special JSON characters in feature name."
);
}
}
if
(
feature_name
.
find
(
' '
)
!=
std
::
string
::
npos
)
{
if
(
feature_name
.
find
(
' '
)
!=
std
::
string
::
npos
)
{
spaceInFeatureName
=
true
;
spaceInFeatureName
=
true
;
...
...
include/LightGBM/utils/common.h
View file @
b2da19b8
...
@@ -927,6 +927,24 @@ inline bool CheckASCII(const std::string& s) {
...
@@ -927,6 +927,24 @@ inline bool CheckASCII(const std::string& s) {
return
true
;
return
true
;
}
}
inline
bool
CheckAllowedJSON
(
const
std
::
string
&
s
)
{
unsigned
char
char_code
;
for
(
auto
c
:
s
)
{
char_code
=
static_cast
<
unsigned
char
>
(
c
);
if
(
char_code
==
34
// "
||
char_code
==
44
// ,
||
char_code
==
58
// :
||
char_code
==
91
// [
||
char_code
==
93
// ]
||
char_code
==
123
// {
||
char_code
==
125
// }
)
{
return
false
;
}
}
return
true
;
}
}
// namespace Common
}
// namespace Common
}
// namespace LightGBM
}
// namespace LightGBM
...
...
src/io/config.cpp
View file @
b2da19b8
...
@@ -21,7 +21,7 @@ void Config::KV2Map(std::unordered_map<std::string, std::string>* params, const
...
@@ -21,7 +21,7 @@ void Config::KV2Map(std::unordered_map<std::string, std::string>* params, const
value
=
Common
::
RemoveQuotationSymbol
(
Common
::
Trim
(
tmp_strs
[
1
]));
value
=
Common
::
RemoveQuotationSymbol
(
Common
::
Trim
(
tmp_strs
[
1
]));
}
}
if
(
!
Common
::
CheckASCII
(
key
)
||
!
Common
::
CheckASCII
(
value
))
{
if
(
!
Common
::
CheckASCII
(
key
)
||
!
Common
::
CheckASCII
(
value
))
{
Log
::
Fatal
(
"Do not support non-
ascii
characters in config."
);
Log
::
Fatal
(
"Do not support non-
ASCII
characters in config."
);
}
}
if
(
key
.
size
()
>
0
)
{
if
(
key
.
size
()
>
0
)
{
auto
value_search
=
params
->
find
(
key
);
auto
value_search
=
params
->
find
(
key
);
...
...
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