mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 20:14:37 +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)
|
static char* _idFromUrl(const char* url)
|
||||||
{
|
{
|
||||||
url = _skipSpace(url, nullptr);
|
auto open = strchr(url, '(');
|
||||||
if ((*url) == '(') {
|
auto close = strchr(url, ')');
|
||||||
++url;
|
if (!open || !close || open >= close) return nullptr;
|
||||||
url = _skipSpace(url, 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;
|
return strDuplicate(open, (close - open + 1));
|
||||||
if ((*url) == '#') ++url;
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
while (url[i] > ' ' && url[i] != ')' && url[i] != '\'') ++i;
|
|
||||||
|
|
||||||
return strDuplicate(url, i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue