matthiasblaesing commented on code in PR #7941: URL: https://github.com/apache/netbeans/pull/7941#discussion_r1842907066
########## platform/openide.util.ui.svg/src/org/openide/util/svg/DenyingElementLoader.java: ########## @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.openide.util.svg; + +import com.github.weisj.jsvg.attributes.AttributeParser; +import com.github.weisj.jsvg.parser.ElementLoader; +import com.github.weisj.jsvg.parser.ParsedDocument; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Set; + +class DenyingElementLoader implements ElementLoader { + private final Set<String> attemptedExternalURLsLoaded = new LinkedHashSet<>(); + + public Set<String> getAttemptedExternalURLsLoaded() { + return Collections.unmodifiableSet(attemptedExternalURLsLoaded); + } + + @Override + public <T> T loadElement(Class<T> type, String value, + ParsedDocument document, AttributeParser attributeParser) + { + /* Same logic as in com.github.weisj.jsvg.parser.DefaultElementLoader for the + AllowExternalResources.DENY case, but gathering up the attempted externally loaded URLs so + we can make the whole loading operation fail and make testLoadImageWithExternalUseXlinkHref + pass. */ + String url = attributeParser.parseUrl(value); + if (url == null) { + return null; + } + if (url.contains("#")) { + String[] parts = url.split("#", 2); + String name = parts[0]; + if (!name.isEmpty()) { + attemptedExternalURLsLoaded.add(value); + return null; + } + return document.getElementById(type, parts[1]); + } else { + return document.getElementById(type, url); Review Comment: From the first part of the logic and the name of the class I understand, that this should deny loading from external resources. If so, I think this else branch should read: ```suggestion attemptedExternalURLsLoaded.add(value); return null; ``` The else part is invoked when no `#` is found in the url. The url is thus a pure external reference and not an internal one. ########## platform/openide.util.ui.svg/test/unit/src/org/openide/util/svg/externalImageHref.svg: ########## @@ -0,0 +1,29 @@ +<?xml version="1.0" standalone="no"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" + "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> + +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<!-- =================================================================== --> +<!-- A dummy document used to preload classes. --> +<!-- =================================================================== --> + +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100"> + <image href="https://example.com/image.png" x="10" y="10" height="160" width="380"/> Review Comment: This is not valid SVG 1.0 (as which it is declared). The correct reference is: ```suggestion <image xlink:href="https://example.com/image.png" x="10" y="10" height="160" width="380"/> ``` The NetBeans XML Validator rightly fails the saved value. I know, that MDN says, that pure `href` is right, but that applies to SVG 2, which is is not final. And there seems to be no grammar provided for SVG2, so there is no DTD or XSD. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
