private boolean getVisitReserved(String tag, boolean resUrl, boolean resTag, String ... attrs) throws Exception { // Reserved when lower-case and both URL and Tag reserved. String attrName = ALL_RESOURCES.get(tag.toLowerCase()); attrName = attrName != null ? attrName : "src"; ArrayList <String> attrsList = Lists.newArrayList(attrs); attrsList.add(0, attrName); attrsList.add(1, URL_STRING); attrs = attrsList.toArray(attrs); Node node = elem(tag, attrs); ContentRewriterFeature.Config config = createMock(ContentRewriterFeature.Config.class); expect(config.shouldRewriteURL(URL_STRING)).andReturn(resUrl).anyTimes(); expect(config.shouldRewriteTag(tag.toLowerCase())).andReturn(resTag).anyTimes(); replay(config); ProxyingVisitor rewriter = new ProxyingVisitor(config, null, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); VisitStatus status = rewriter.visit(null, node); verify(config); return status != VisitStatus.BYPASS; }
private boolean getVisitReserved(String tag, boolean resUrl, boolean resTag, String ... attrs) throws Exception { // Reserved when lower-case and both URL and Tag reserved. String attrName = ALL_RESOURCES.get(tag.toLowerCase()); attrName = attrName != null ? attrName : "src"; ArrayList <String> attrsList = Lists.newArrayList(attrs); attrsList.add(0, attrName); attrsList.add(1, URL_STRING); attrs = attrsList.toArray(attrs); Node node = elem(tag, attrs); ContentRewriterFeature.Config config = createMock(ContentRewriterFeature.Config.class); expect(config.shouldRewriteURL(URL_STRING)).andReturn(resUrl).anyTimes(); expect(config.shouldRewriteTag(tag.toLowerCase())).andReturn(resTag).anyTimes(); replay(config); ProxyingVisitor rewriter = new ProxyingVisitor(config, null, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); VisitStatus status = rewriter.visit(null, node); verify(config); return status != VisitStatus.BYPASS; }
private boolean getVisitReserved(String tag, boolean resUrl, boolean resTag, String ... attrs) throws Exception { // Reserved when lower-case and both URL and Tag reserved. String attrName = ALL_RESOURCES.get(tag.toLowerCase()); attrName = attrName != null ? attrName : "src"; ArrayList <String> attrsList = Lists.newArrayList(attrs); attrsList.add(0, attrName); attrsList.add(1, URL_STRING); attrs = attrsList.toArray(attrs); Node node = elem(tag, attrs); ContentRewriterFeature.Config config = createMock(ContentRewriterFeature.Config.class); expect(config.shouldRewriteURL(URL_STRING)).andReturn(resUrl).anyTimes(); expect(config.shouldRewriteTag(tag.toLowerCase())).andReturn(resTag).anyTimes(); replay(config); ProxyingVisitor rewriter = new ProxyingVisitor(config, null, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); VisitStatus status = rewriter.visit(null, node); verify(config); return status != VisitStatus.BYPASS; }
@Test public void imgWithEmptySrc() throws Exception { Node node = elem("img", "src", ""); ContentRewriterFeature.Config config = createMock(ContentRewriterFeature.Config.class); expect(config.shouldRewriteURL("")).andReturn(true).anyTimes(); expect(config.shouldRewriteTag("img")).andReturn(true).anyTimes(); replay(config); ProxyingVisitor rewriter = new ProxyingVisitor(config, null, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); VisitStatus status = rewriter.visit(null, node); verify(config); assertEquals("Empty attribute should not be rewritten", VisitStatus.BYPASS, status); }
@Test public void imgWithEmptySrc() throws Exception { Node node = elem("img", "src", ""); ContentRewriterFeature.Config config = createMock(ContentRewriterFeature.Config.class); expect(config.shouldRewriteURL("")).andReturn(true).anyTimes(); expect(config.shouldRewriteTag("img")).andReturn(true).anyTimes(); replay(config); ProxyingVisitor rewriter = new ProxyingVisitor(config, null, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); VisitStatus status = rewriter.visit(null, node); verify(config); assertEquals("Empty attribute should not be rewritten", VisitStatus.BYPASS, status); }
@Test public void imgWithEmptySrc() throws Exception { Node node = elem("img", "src", ""); ContentRewriterFeature.Config config = createMock(ContentRewriterFeature.Config.class); expect(config.shouldRewriteURL("")).andReturn(true).anyTimes(); expect(config.shouldRewriteTag("img")).andReturn(true).anyTimes(); replay(config); ProxyingVisitor rewriter = new ProxyingVisitor(config, null, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); VisitStatus status = rewriter.visit(null, node); verify(config); assertEquals("Empty attribute should not be rewritten", VisitStatus.BYPASS, status); }
Element e1 = elem("script", "src", scriptSrc); Element e2 = elem("script", "src", "^!,,|BLARGH"); Element e3 = elem("IMG", "src", imgSrc); Element e4 = elem("script", "src", " " + scriptSrc + " "); List<Node> nodes = ImmutableList.<Node>of(e1, e2, e3, e4); ProxyUriManager uriManager = createMock(ProxyUriManager.class);
Element e1 = elem("script", "src", scriptSrc); Element e2 = elem("script", "src", "^!,,|BLARGH"); Element e3 = elem("IMG", "src", imgSrc); Element e4 = elem("script", "src", " " + scriptSrc + " "); List<Node> nodes = ImmutableList.<Node>of(e1, e2, e3, e4); ProxyUriManager uriManager = createMock(ProxyUriManager.class);
Element e1 = elem("script", "src", scriptSrc); Element e2 = elem("script", "src", "^!,,|BLARGH"); Element e3 = elem("IMG", "src", imgSrc); Element e4 = elem("script", "src", " " + scriptSrc + " "); List<Node> nodes = ImmutableList.<Node>of(e1, e2, e3, e4); ProxyUriManager uriManager = createMock(ProxyUriManager.class);