 Issue 29480569:
  Issue 5254 - Improve URL verification when whitelisting domains  (Closed)
    
  
    Issue 29480569:
  Issue 5254 - Improve URL verification when whitelisting domains  (Closed) 
  | Left: | ||
| Right: | 
| OLD | NEW | 
|---|---|
| 1 /* | 1 /* | 
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 
| 3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH | 
| 4 * | 4 * | 
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify | 
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as | 
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. | 
| 8 * | 8 * | 
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, | 
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. | 
| 13 * | 13 * | 
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License | 
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 
| 16 */ | 16 */ | 
| 17 | 17 | 
| 18 package org.adblockplus.sbrowser.contentblocker; | 18 package org.adblockplus.sbrowser.contentblocker; | 
| 19 | 19 | 
| 20 import android.app.AlertDialog; | 20 import android.app.AlertDialog; | 
| 21 import android.content.Context; | 21 import android.content.Context; | 
| 22 import android.os.Bundle; | 22 import android.os.Bundle; | 
| 23 import android.preference.EditTextPreference; | 23 import android.preference.EditTextPreference; | 
| 24 import android.text.Editable; | 24 import android.text.Editable; | 
| 25 import android.text.InputType; | 25 import android.text.InputType; | 
| 26 import android.text.TextWatcher; | 26 import android.text.TextWatcher; | 
| 27 import android.util.AttributeSet; | 27 import android.util.AttributeSet; | 
| 28 import android.util.Patterns; | |
| 29 import android.view.KeyEvent; | 28 import android.view.KeyEvent; | 
| 30 import android.view.View; | 29 import android.view.View; | 
| 31 import android.view.inputmethod.EditorInfo; | 30 import android.view.inputmethod.EditorInfo; | 
| 32 import android.widget.EditText; | 31 import android.widget.EditText; | 
| 33 import android.widget.TextView; | 32 import android.widget.TextView; | 
| 34 import android.widget.Toast; | 33 import android.widget.Toast; | 
| 35 | 34 | 
| 36 import org.adblockplus.adblockplussbrowser.R; | 35 import org.adblockplus.adblockplussbrowser.R; | 
| 37 import org.adblockplus.sbrowser.contentblocker.util.PreferenceUtils; | 36 import org.adblockplus.sbrowser.contentblocker.util.PreferenceUtils; | 
| 37 import org.apache.commons.validator.routines.DomainValidator; | |
| 38 | 38 | 
| 39 public class UrlInputOpenerPreference extends EditTextPreference implements Text Watcher, | 39 public class UrlInputOpenerPreference extends EditTextPreference implements Text Watcher, | 
| 40 TextView.OnEditorActionListener | 40 TextView.OnEditorActionListener | 
| 41 { | 41 { | 
| 42 | 42 | 
| 43 private OnUrlReadyListener onUrlReadyListener; | 43 private OnUrlReadyListener onUrlReadyListener; | 
| 44 private AlertDialog mAlertDialog; | 44 private AlertDialog mAlertDialog; | 
| 45 | 45 | 
| 46 public UrlInputOpenerPreference(Context context) | 46 public UrlInputOpenerPreference(Context context) | 
| 47 { | 47 { | 
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 PreferenceUtils.setMultilineTitle(view); | 127 PreferenceUtils.setMultilineTitle(view); | 
| 128 } | 128 } | 
| 129 | 129 | 
| 130 public void setOnUrlReadyListener(OnUrlReadyListener listener) | 130 public void setOnUrlReadyListener(OnUrlReadyListener listener) | 
| 131 { | 131 { | 
| 132 this.onUrlReadyListener = listener; | 132 this.onUrlReadyListener = listener; | 
| 133 } | 133 } | 
| 134 | 134 | 
| 135 private boolean isValidUrl() | 135 private boolean isValidUrl() | 
| 136 { | 136 { | 
| 137 return Patterns.WEB_URL.matcher(getUrl()).matches(); | 137 return DomainValidator.getInstance().isValid(getUrl()); | 
| 
anton
2017/07/06 06:51:10
it's misleading - we validate URL with Apache DOMA
 
jens
2017/07/06 08:49:06
The purpose of this change is, to have a reliable
 | |
| 138 } | 138 } | 
| 139 | 139 | 
| 140 private String getUrl() | 140 private String getUrl() | 
| 141 { | 141 { | 
| 142 return getEditText().getText().toString(); | 142 return getEditText().getText().toString(); | 
| 143 } | 143 } | 
| 144 | 144 | 
| 145 private void setPositiveButtonEnabled(boolean enabled) | 145 private void setPositiveButtonEnabled(boolean enabled) | 
| 146 { | 146 { | 
| 147 if (mAlertDialog != null) | 147 if (mAlertDialog != null) | 
| 148 { | 148 { | 
| 149 mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(enabled); | 149 mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(enabled); | 
| 150 } | 150 } | 
| 151 } | 151 } | 
| 152 | 152 | 
| 153 public interface OnUrlReadyListener | 153 public interface OnUrlReadyListener | 
| 154 { | 154 { | 
| 155 void onUrlReady(String url); | 155 void onUrlReady(String url); | 
| 156 } | 156 } | 
| 157 } | 157 } | 
| OLD | NEW |