mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-08-23 17:17:31 -04:00
add https to valid url
This commit is contained in:
parent
5b4cacfcc4
commit
cea98c332d
5 changed files with 1344 additions and 9 deletions
|
@ -36,6 +36,7 @@ AnalyticsEvents="*res://scripts/api/analytics/analytics_events.gd"
|
|||
Backend="*res://scripts/api/backend.gd"
|
||||
Navigation="*res://scenes/autoloads/navigation.tscn"
|
||||
AfkManager="*res://scripts/afk_manager.gd"
|
||||
Url="*res://scenes/autoloads/url.tscn"
|
||||
|
||||
[debug]
|
||||
|
||||
|
|
1289
app/resources/tld_list.txt
Normal file
1289
app/resources/tld_list.txt
Normal file
File diff suppressed because it is too large
Load diff
7
app/scenes/autoloads/url.tscn
Normal file
7
app/scenes/autoloads/url.tscn
Normal file
|
@ -0,0 +1,7 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://ibqfwrvrximj"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/url.gd" id="1_jqily"]
|
||||
|
||||
[node name="Url" type="Node"]
|
||||
script = ExtResource("1_jqily")
|
||||
tld_list_file = "res://resources/tld_list.txt"
|
|
@ -54,5 +54,4 @@ func hide_message() -> void:
|
|||
|
||||
func reload_gate() -> void:
|
||||
var location = history.get_current()
|
||||
if Url.is_valid(location):
|
||||
gate_events.open_gate_emit(location)
|
||||
gate_events.open_gate_emit(location)
|
||||
|
|
|
@ -1,10 +1,25 @@
|
|||
extends RefCounted
|
||||
class_name Url
|
||||
extends Node
|
||||
# class_name Url
|
||||
|
||||
const url_regex: String = "^(https?)://[^\\s()<>]+(?:\\([\\w\\d]+\\)|([^[:punct:]\\s]|/))$"
|
||||
|
||||
@export_file("*.txt") var tld_list_file: String
|
||||
|
||||
static func join(base_url: String, path: String) -> String:
|
||||
var regex: RegEx
|
||||
var tld_list: Dictionary = {}
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
regex = RegEx.new()
|
||||
regex.compile(url_regex)
|
||||
|
||||
var file = FileAccess.open(tld_list_file, FileAccess.READ)
|
||||
var tlds = file.get_as_text().split("\n")
|
||||
for tld in tlds:
|
||||
tld_list[tld] = true
|
||||
|
||||
|
||||
func join(base_url: String, path: String) -> String:
|
||||
var url = ""
|
||||
if path.is_empty():
|
||||
url = ""
|
||||
|
@ -15,15 +30,39 @@ static func join(base_url: String, path: String) -> String:
|
|||
return url
|
||||
|
||||
|
||||
static func fix_gate_url(url: String) -> String:
|
||||
func fix_gate_url(url: String) -> String:
|
||||
if not url.begins_with("http://") and not url.begins_with("https://"):
|
||||
url = "https://" + url
|
||||
|
||||
if url.get_extension() != "gate":
|
||||
var slash = "" if url.ends_with("/") else "/"
|
||||
url += slash + "world.gate"
|
||||
|
||||
url = lower_domain(url)
|
||||
return url
|
||||
|
||||
|
||||
static func is_valid(url: String) -> bool:
|
||||
var regex = RegEx.new()
|
||||
regex.compile(url_regex)
|
||||
func is_valid(url: String) -> bool:
|
||||
if not url.begins_with("http://") and not url.begins_with("https://"):
|
||||
var domain = url.split("/")[0]
|
||||
if is_valid_domain(domain):
|
||||
url = "https://" + url
|
||||
|
||||
var result = regex.search(url)
|
||||
return false if result == null else result.get_string() == url
|
||||
|
||||
|
||||
func lower_domain(url: String) -> String:
|
||||
# Assuming https?://domain/*.gate
|
||||
var split = url.split("/", true, 3)
|
||||
assert(split.size() == 4, "Invalid URL: " + url)
|
||||
|
||||
var domain = split[2]
|
||||
return split[0] + "//" + domain.to_lower() + "/" + split[3]
|
||||
|
||||
|
||||
func is_valid_domain(domain: String) -> bool:
|
||||
if domain.is_empty() or domain.split(".").size() != 2:
|
||||
return false
|
||||
|
||||
return tld_list.has(domain.get_extension().to_lower())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue