mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
svg: Improve valid check for url(#id)
Improve parenthesis checking and space checking. - There must be only one pair of parentheses. - There cannot be spaces(and ') between id strings. Issue: https://github.com/thorvg/thorvg/issues/1983 Co-authored-by: Hermet Park <hermet@lottiefiles.com>
This commit is contained in:
parent
2087db7ebf
commit
c6cf9cb2cf
1 changed files with 17 additions and 11 deletions
|
@ -378,19 +378,25 @@ static void _parseDashArray(SvgLoaderData* loader, const char *str, SvgDash* das
|
|||
|
||||
static char* _idFromUrl(const char* url)
|
||||
{
|
||||
url = _skipSpace(url, nullptr);
|
||||
if ((*url) == '(') {
|
||||
++url;
|
||||
url = _skipSpace(url, nullptr);
|
||||
auto open = strchr(url, '(');
|
||||
auto close = strchr(url, ')');
|
||||
if (!open || !close || open >= close) return nullptr;
|
||||
|
||||
open = strchr(url, '#');
|
||||
if (!open || open >= close) return nullptr;
|
||||
|
||||
++open;
|
||||
--close;
|
||||
|
||||
//trim the rest of the spaces if any
|
||||
while (open < close && *close == ' ') --close;
|
||||
|
||||
//quick verification
|
||||
for (auto id = open; id < close; id++) {
|
||||
if (*id == ' ' || *id == '\'') return nullptr;
|
||||
}
|
||||
|
||||
if ((*url) == '\'') ++url;
|
||||
if ((*url) == '#') ++url;
|
||||
|
||||
int i = 0;
|
||||
while (url[i] > ' ' && url[i] != ')' && url[i] != '\'') ++i;
|
||||
|
||||
return strDuplicate(url, i);
|
||||
return strDuplicate(open, (close - open + 1));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue