Skip to content

Commit

Permalink
Merge pull request #374 from ldko/fix-371-integrity-attribute
Browse files Browse the repository at this point in the history
Fix 371 integrity attribute
  • Loading branch information
ldko committed Mar 6, 2018
2 parents 680fba1 + d5cfca6 commit 795e61e
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/site/markdown/release_notes.md
Expand Up @@ -17,6 +17,7 @@ Full listing of changes and bug fixes are not available prior to release 1.2.0 a
* Fix inconsistent content and background image shifting with toolbar and disclaimer. [#358](https://github.com/iipc/openwayback/issues/358)
* Fix misplaced `break` statement in WatchedCDXSource. [#369](https://github.com/iipc/openwayback/issues/369)
* Fix toolbar plurality issue when only a single capture. [#372](https://github.com/iipc/openwayback/issues/372)
* Rewrite `integrity` attribute for resources that implement Subresource Integrity. [#371](https://github.com/iipc/openwayback/issues/371)

## OpenWayback 2.3.2 Release
### Bug fixes
Expand Down
Expand Up @@ -16,6 +16,7 @@
import org.archive.wayback.replay.html.transformer.InlineCSSStringTransformer;
import org.archive.wayback.replay.html.transformer.JSStringTransformer;
import org.archive.wayback.replay.html.transformer.MetaRefreshUrlStringTransformer;
import org.archive.wayback.replay.html.transformer.RegexReplaceStringTransformer;
import org.archive.wayback.replay.html.transformer.SrcsetStringTransformer;
import org.archive.wayback.replay.html.transformer.URLStringTransformer;
import org.htmlparser.nodes.TagNode;
Expand Down Expand Up @@ -225,6 +226,7 @@ protected void initTransformers() {
transformers.put("ci", new InlineCSSStringTransformer());
transformers.put("mt", new MetaRefreshUrlStringTransformer());
transformers.put("ss", new SrcsetStringTransformer());
transformers.put("in", new RegexReplaceStringTransformer("^.*$", ""));

if (customTransformers != null) {
transformers.putAll(customTransformers);
Expand Down
Expand Up @@ -42,6 +42,19 @@ public class RegexReplaceStringTransformer extends RewriteRule implements
// being removed
private String urlScope = null;

/** Default constructor */
public RegexReplaceStringTransformer() {}

/**
* regex/replacement setting constructor.
* @param regex String to be replaced
* @param replacement String to use
*/
public RegexReplaceStringTransformer(String regex, String replacement) {
setRegex(regex);
this.replacement = replacement;
}

public String transform(ReplayParseContext context, String input) {

if (getName() != null) {
Expand Down
Expand Up @@ -21,12 +21,14 @@ IMG.SRCSET.type=ss
INPUT.SRC.type=im
FORM.ACTION.type=an
FRAME.SRC.type=fw
LINK.INTEGRITY.type=in
LINK[REL\=STYLESHEET].HREF.type=cs
LINK[REL\=SHORTCUT\ ICON].HREF.type=im
META[HTTP-EQUIV\=REFRESH].CONTENT.type=mt
META.URL.type=an
OBJECT.CODEBASE.type=oe
OBJECT.CDATA.type=oe
SCRIPT.INTEGRITY.type=in
SCRIPT.SRC.type=js
SOURCE.SRCSET.type=ss
# HTML5 -- can have data-src or data-uri attributes in any tag!
Expand Down
@@ -0,0 +1,59 @@
/*
*
*/
package org.archive.wayback.replay.html.transformer;

import java.net.URL;

import junit.framework.TestCase;

import org.archive.wayback.replay.html.transformer.JSStringTransformerTest.RecordingReplayParseContext;

/**
* unit test for {@link RegexReplaceStringTransformer}.
*
*/
public class RegexReplaceStringTransformerTest extends TestCase {

URL baseURL;
RecordingReplayParseContext rc;
RegexReplaceStringTransformer st;

/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
baseURL = new URL("http://foo.com");
rc = new RecordingReplayParseContext(null, baseURL, null);
}

public void testTransform() throws Exception {
// values are input, regex to find, replacement for regex, expected result
final String[][] cases = new String[][] {
{
"sha256-1LpauPYMnfXHM+fTx8Rp/5Pca2TSsqj+uUr6j3fGYZM=",
".*sha256.*",
"",
"",
},
{
"examples/video/test.mp4",
"video/[a-z]*.mp4",
"video/changed.mp4",
"examples/video/changed.mp4",
},
{
"examples/video/test.mp4",
"notmatching/[a-z]*.mp4",
"video/changed.mp4",
"examples/video/test.mp4",
}
};

for (String[] c : cases) {
st = new RegexReplaceStringTransformer(c[1], c[2]);
String result = st.transform(rc, c[0]);
assertEquals(c[3], result);
}
}
}

0 comments on commit 795e61e

Please sign in to comment.