Skip to content

Commit

Permalink
Update parser.cpp
Browse files Browse the repository at this point in the history
Support quoted URL value
  • Loading branch information
Nwutobo Samuel Ugochukwu authored May 19, 2022
1 parent 7f82e94 commit 984ddfd
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions source/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,22 @@ std::string Parser::parseUrl(const std::string& string)
auto ptr = string.data();
auto end = ptr + string.size();

if(!Utils::skipDesc(ptr, end, "url(#"))
if(!Utils::skipDesc(ptr, end, "url(")
|| !Utils::skipWs(ptr, end)) {
return std::string{};
}

std::string value;
if(!Utils::readUntil(ptr, end, ')', value))
char delim = ')';
if(*ptr == '\'' || *ptr == '"') {
delim = *ptr;
++ptr;
}

if(!Utils::skipDesc(ptr, end, '#'))
return std::string{};

std::string value;
Utils::readUntil(ptr, end, delim, value);
return value;
}

Expand Down Expand Up @@ -744,11 +753,28 @@ Paint Parser::parsePaint(const std::string& string, const StyledElement* element
auto ptr = string.data();
auto end = ptr + string.size();

if(!Utils::skipDesc(ptr, end, "url(#"))
if(!Utils::skipDesc(ptr, end, "url("))
return parseColor(string, element, defaultValue);

if(!Utils::skipWs(ptr, end))
return defaultValue;

char delim = ')';
if(*ptr == '\'' || *ptr == '"') {
delim = *ptr;
++ptr;
}

std::string ref;
if(!Utils::readUntil(ptr, end, ')', ref))
if(!Utils::skipDesc(ptr, end, '#')
|| !Utils::readUntil(ptr, end, delim, ref)) {
return defaultValue;
}

if(ptr == '\'' || *ptr == '"')
++ptr;

if(ptr >= end || *ptr != ')')
return defaultValue;

++ptr;
Expand Down

0 comments on commit 984ddfd

Please sign in to comment.