Skip to content

Commit

Permalink
Merge pull request #11 from brunobar79/fix-android-head-tag-match
Browse files Browse the repository at this point in the history
Fix android head tag match
  • Loading branch information
Bruno Barbieri authored Jul 25, 2019
2 parents c636371 + 8551369 commit 7f58566
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class InputStreamWithInjectedJS extends InputStream {
private boolean hasJS = false;
private boolean headWasFound = false;
private boolean scriptWasInjected = false;
private boolean openingHeadFound = false;
private StringBuffer contentBuffer = new StringBuffer();
private static Charset getCharset(String charsetName) {
Charset cs = UTF_8;
Expand Down Expand Up @@ -63,6 +64,7 @@ public int read() throws IOException {
if (scriptWasInjected || !hasJS) {
return pageIS.read();
}

if (!scriptWasInjected && headWasFound) {
int nextByte = scriptIS.read();
if (nextByte == -1) {
Expand All @@ -75,12 +77,22 @@ public int read() throws IOException {
}
if (!headWasFound) {
int nextByte = pageIS.read();
contentBuffer.append((char) nextByte);
char nextByteStr = (char) nextByte;
contentBuffer.append(nextByteStr);
int bufferLength = contentBuffer.length();
if (nextByte == 62 && bufferLength >= 6) {
if (contentBuffer.substring(bufferLength - 6).equals("<head>")) {
String headString = "<head";
if(openingHeadFound){
if(nextByte == 62){
this.scriptIS = getScript(this.charset);
headWasFound = true;
}
} else {
boolean isLetterD = (nextByte == 68 || nextByte == 100);
if (isLetterD && bufferLength >= 5) {
String stringToMatch = contentBuffer.substring(bufferLength - 5).toLowerCase();
if (stringToMatch.contains(headString)) {
openingHeadFound = true;
}
}
}
return nextByte;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-web3-webview",
"version": "2.0.0",
"version": "2.0.1",
"description": "A react native webview optimized for a web3 dApp browser application",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 7f58566

Please sign in to comment.