0
0
mirror of https://github.com/TrianguloY/UrlChecker.git synced 2024-09-19 20:02:16 +02:00

fix no protocol when clearing with clearUrl, and adds a pattern check to insert if missing

closes #28
This commit is contained in:
TrianguloY 2022-07-17 14:02:33 +02:00
parent 5b982c6e11
commit 778b6266e8
3 changed files with 36 additions and 13 deletions

View File

@ -258,17 +258,26 @@ class ClearUrlDialog extends AModuleDialog implements View.OnClickListener {
}
}
// fix empty elements
cleared = cleared
.replaceAll("\\?&+", "?")
.replaceAll("\\?#", "#")
.replaceAll("\\?$", "")
.replaceAll("&&+", "&")
.replaceAll("&#", "#")
.replaceAll("&$", "")
.replaceAll("#&+", "#")
.replaceAll("#$", "")
;
// if changed, fix cleaning artifacts
if (!cleared.equals(urlData.url)) {
// remove empty elements
cleared = cleared
.replaceAll("\\?&+", "?")
.replaceAll("\\?#", "#")
.replaceAll("\\?$", "")
.replaceAll("&&+", "&")
.replaceAll("&#", "#")
.replaceAll("&$", "")
.replaceAll("#&+", "#")
.replaceAll("#$", "")
;
// restore missing domain
if (!cleared.matches("^https?://.*")) {
cleared = "http://" + cleared;
}
}
}
} catch (JSONException | UnsupportedEncodingException e) {

View File

@ -73,10 +73,15 @@ class PatternDialog extends AModuleDialog implements ClickableLinks.OnUrlListene
}
// check for http
if (url.startsWith("http:")) {
if (url.startsWith("http://")) {
messages.add(getActivity().getString(R.string.mPttrn_http));
}
// check for missing protocol
if (!url.matches("^https?://.*")) {
messages.add(getActivity().getString(R.string.mPttrn_noProtocol));
}
// TODO: other checks?
if (messages.isEmpty()) {
@ -102,7 +107,15 @@ class PatternDialog extends AModuleDialog implements ClickableLinks.OnUrlListene
switch (tag) {
case "http":
// replace http with https
setUrl(getUrl().replaceFirst("^http:", "https:"));
setUrl(getUrl().replaceFirst("^http://", "https://"));
break;
case "+http":
// prepend http
setUrl("http://" + getUrl());
break;
case "+https":
// prepend https
setUrl("https://" + getUrl());
break;
}
}

View File

@ -35,6 +35,7 @@ Translation help from: Tiago Carmo, Ilithy, Idris."</string>
* http links, you should use https instead"</string>
<string name="mPttrn_ascii">Warning! Non ascii characters found "%s"</string>
<string name="mPttrn_http">Http link, consider using https: [[http|Fix]]</string>
<string name="mPttrn_noProtocol">Missing protocol. [[+http|Add http]] or [[+https|add https]]</string>
<string name="mPttrn_ok">No issues found</string>
<string name="mOpen_name"><![CDATA[Open & Share]]></string>