phax / ph-css

Advanced Java CSS 3 parser and builder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

URI Traversing misses uris within functions

rockwotj opened this issue · comments

Example CSS:

dd {
    background-image: cross-fade(20% url(http://example.com/first.png), url(/second.png));
}

I would expect that this example: https://github.com/phax/ph-css/blob/master/ph-css/src/test/java/com/helger/css/supplementary/wiki/WikiVisitDataUrls.java

Would print out urls for this snippet, but it does not.

I'm able to fix this in kotlin with something like:

private inner class CompleteCSSVisitorForUrl(visitor: ICSSUrlVisitor) : CSSVisitorForUrl(visitor) {
        override fun onDeclaration(decl: CSSDeclaration) {
            val expr = decl.expression
            onExpression(decl, expr)
        }

        private fun onExpression(decl: CSSDeclaration, expr: CSSExpression) {
            for (member in expr.allMembers) when (member) {
                is CSSExpressionMemberTermURI -> {
                    visitor.onUrlDeclaration(null, decl, member)
                }
                is CSSExpressionMemberFunction -> {
                    member.expression?.let { onExpression(decl, it) }
                }
            }
        }
    }

Obviously this isn't quite correct WRT to the visitor interface, but works for my usecase.

Thank you for that snippet 👍
So what you basically suggest is to add a flag "visit nested expressions" in the general visitor and enable this flag by default in the URL Visitor?
There are other patterns as well e.g. in a "math" function an expression can be contained

Ah forget half of my previous comment. I just fix the CSSVisitorForUrl

This is part of the 6.2.3 release that is building as I type

Wow thanks for the quick turnaround and release here!