Fine0830 commented on PR #115:
URL: 
https://github.com/apache/skywalking-client-js/pull/115#issuecomment-1765738244

   > > > > > > > When the match variable is null, the url will be '', and 
reading match[1] will result in a runtime error.
   > > > > > > 
   > > > > > > 
   > > > > > > I did not reproduce this issue, and the `match && match[1]` is 
in codes, I don't think the error will happen.
   > > > > > 
   > > > > > 
   > > > > > @Fine0830
   > > > > > ```
   > > > > > // background-image: url('https://www.example.com/test.png')
   > > > > > const match = getStyle(item.ele, 
'background-image').match(/url\(\"(.*?)\"\)/);
   > > > > > let url: string = '';
   > > > > > if (match && match[1]) { // match would be null and this branch 
would not be executed
   > > > > >   url = match[1];
   > > > > > }
   > > > > > if (!url.includes('http')) { // url would be '' and this branch 
would be executed
   > > > > >   url = location.protocol + match[1]; // throw a error when read 
property 1 from match, because match would be null
   > > > > > }
   > > > > > ```
   > > > > 
   > > > > 
   > > > > I gave it a try but get `match` is 
`['url("https://www.example.com/test.png";)', 
'https://www.example.com/test.png', index: 0, input: 
'url("https://www.example.com/test.png";)', groups: undefined]`, not `null`.
   > > > 
   > > > 
   > > > The regular expression does not account for matching URLs with single 
quotes or URLs without any quotes.
   > > 
   > > 
   > > Could you explain what is the `background-image` value in your case?
   > 
   > background-image: url('https://www.example.com/test.png'); // single 
quotes background-image: url("https://www.example.com/test.png";); // double 
quotes background-image: url(https://www.example.com/test.png); // without any 
quotes
   
   I have checked those three parameters, the `getStyle` always return a value 
like `url("https://www.example.com/test.png";)`. And I haven't found the `match` 
value will be `null`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to