Skip to content

Commit c7e9fbd

Browse files
committed
Update
1 parent 287acd9 commit c7e9fbd

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

app/src/main/java/com/tool/tree/AnsiColorParser.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,18 @@ object AnsiColorParser {
277277

278278
var url = text.substring(start, end)
279279

280+
// CHỈ coi là link khi văn bản THỰC SỰ bắt đầu bằng http:// hoặc https://.
281+
// Patterns.WEB_URL của Android mặc định khớp CẢ domain trần không có scheme
282+
// (vd "Kakathic.com", "example.com") -> nếu không lọc lại ở đây, những đoạn
283+
// text bình thường như "echo "Kakathic.com"" cũng sẽ bị biến thành link, dù
284+
// người dùng không hề gõ http(s)://. Bỏ qua (không gắn URLSpan) cho mọi match
285+
// không có scheme http/https tường minh, và KHÔNG tự thêm "http://" vào nữa.
286+
if (!url.startsWith("http://", ignoreCase = true) &&
287+
!url.startsWith("https://", ignoreCase = true)
288+
) {
289+
continue
290+
}
291+
280292
// Bỏ các dấu câu/ngoặc thường bị dính vào cuối URL do nằm trong câu văn
281293
// (vd: "xem tại https://example.com." hoặc "(https://example.com)")
282294
while (end > start && url.isNotEmpty() && url.last() in ".,;:!?)]}\"'") {
@@ -285,15 +297,7 @@ object AnsiColorParser {
285297
}
286298
if (url.isEmpty()) continue
287299

288-
// Patterns.WEB_URL cho phép URL không có scheme (vd "example.com"); URLSpan cần scheme
289-
// đầy đủ để Intent.ACTION_VIEW mở đúng trình duyệt.
290-
val fullUrl = if (url.startsWith("http://", ignoreCase = true) ||
291-
url.startsWith("https://", ignoreCase = true)
292-
) {
293-
url
294-
} else {
295-
"http://$url"
296-
}
300+
val fullUrl = url
297301

298302
builder.setSpan(
299303
URLSpan(fullUrl),

0 commit comments

Comments
 (0)