no message

This commit is contained in:
Vitor Pamplona
2026-03-23 18:16:24 -04:00
5 changed files with 112 additions and 4 deletions
@@ -71,7 +71,7 @@
<string name="quote">Zacytuj</string>
<string name="fork">Sklonuj</string>
<string name="propose_an_edit">Zaproponuj zmianę</string>
<string name="new_amount_in_sats">Nowa kwota w Satsach</string>
<string name="new_amount_in_sats">Nowa kwota w satoszach</string>
<string name="add">Dodaj</string>
<string name="replying_to">"odpowiadając do "</string>
<string name="and">" i "</string>
@@ -92,7 +92,7 @@
<string name="lightning_tips">Lightning transfer</string>
<string name="note_to_receiver">Wiadomość dla odbiorcy</string>
<string name="thank_you_so_much">Dziękuję bardzo!</string>
<string name="amount_in_sats">Kwota w Satsach</string>
<string name="amount_in_sats">Kwota w satoszach</string>
<string name="send_sats">Wyślij</string>
<string name="secret_emoji_maker">Kreator tajnych emoji</string>
<string name="secret_emoji_maker_explainer">Dodaj emoji z ukrytą wiadomością do wpisu</string>
@@ -1101,6 +1101,13 @@
<string name="new_community_note">Nowy wpis w społeczności</string>
<string name="new_product">Nowy produkt</string>
<string name="new_exclusive_geo_note">Nowy GEO-ekskluzywny Wpis</string>
<string name="new_long_form_post">Nowy artykuł</string>
<string name="article_title">Tytuł</string>
<string name="article_summary">Podsumowanie (opcjonalnie)</string>
<string name="article_cover_image_url">Adres URL miniaturki (opcjonalnie)</string>
<string name="write_your_article_in_markdown">Napisz artykuł w formacie markdown…</string>
<string name="markdown_preview">Podgląd</string>
<string name="markdown_edit">Edytuj</string>
<string name="open_all_reactions_to_this_post">Otwórz wszystkie odzewy na ten post</string>
<string name="close_all_reactions_to_this_post">Zamknij wszystkie odzewy na ten post</string>
<string name="reply_description">Odpowiedź</string>
@@ -1238,6 +1245,7 @@
<string name="existed_since">OTS: %1$s</string>
<string name="ots_info_title">Potwierdzenie znacznika czasu</string>
<string name="ots_info_description">Istnieje dowód na to, że ten post został podpisany przed %1$s. Dowód został opatrzony pieczęcią w łańcuchu bloków Bitcoin w tym dniu i czasie.</string>
<string name="edit_article">Redaguj artykuł</string>
<string name="edit_post">Edytuj wpis</string>
<string name="proposal_to_edit">Propozycja ulepszenia wpisu</string>
<string name="message_to_author">Podsumowanie zmian</string>
@@ -1560,6 +1568,7 @@
<string name="name_search_npub1_alice_example_com">wyszukaj, npub1…, alicja@domena.pl</string>
<string name="supports_npub_nip_05_hex_and_namecoin_bit_d_id">Obsługuje npub, nprofile, NIP-05, hex, i namecoin (.bit, d/, id/)</string>
<string name="look_up_follow_list">Sprawdź listę obserwowanych</string>
<string name="tip">Porada</string>
<string name="accounts_found">Znaleziono %1$d kont(a)</string>
<string name="num_selected">Wybrano: %1$d</string>
<string name="resolved_via_namecoin">Rozwiązane przez Namecoin</string>
@@ -1659,4 +1668,11 @@
<string name="attestor_proficiency_for_kinds">Biegłość w sprawdzaniu typów: %1$s</string>
<string name="attestation_attests_to">Certyfikat dla</string>
<string name="attestation_requests_attestation_to">Żądanie certyfikatu do</string>
<string name="event_sync_date_filter_title">Przedział czasu</string>
<string name="event_sync_date_filter_since">Od</string>
<string name="event_sync_date_filter_until">Do</string>
<string name="event_sync_date_filter_now">Teraz</string>
<string name="event_sync_date_filter_all_time">Cały czas</string>
<string name="event_sync_date_filter_last_sync">Ostatnia synchronizacja %1$s</string>
<string name="event_sync_date_filter_since_last_sync">Od ostatniej synchronizacji</string>
</resources>
@@ -281,6 +281,18 @@ class UrlParserTest {
Urls(withScheme = emptySet()),
)
/**
* Regression test for PR #1907: parsing a note whose content is only the Japanese phrase
* "今北産業" (a common internet abbreviation) must not throw a StringIndexOutOfBoundsException
* from Url.getPart() and must produce no detected URLs.
*/
@Test
fun testImakitaSangyo() =
test(
"今北産業",
Urls(),
)
@Test
fun testHour() =
test(
@@ -228,11 +228,17 @@ class Url(
return null
}
val startIndex = urlMarker.indexOf(part)
if (startIndex < 0 || startIndex >= originalUrl.length) {
return null
}
val nextPart = nextExistingPart(part)
return if (nextPart == null) {
originalUrl.substring(urlMarker.indexOf(part))
originalUrl.substring(startIndex)
} else {
originalUrl.substring(urlMarker.indexOf(part), urlMarker.indexOf(nextPart))
val endIndex = urlMarker.indexOf(nextPart)
originalUrl.substring(startIndex, minOf(endIndex, originalUrl.length))
}
}
@@ -41,4 +41,14 @@ class UrlsDetectorTest {
assertContains(detectedLinks, "https://mysite.xyz")
assertContains(detectedLinks, "https://myblog.xyz")
}
/**
* Regression test for PR #1907: the Japanese phrase "今北産業" must not crash the URL
* detector with a StringIndexOutOfBoundsException and must return no URLs.
*/
@Test
fun doesNotCrashOnJapaneseText() {
val detectedLinks = fastFindURLs("今北産業")
assertEquals(0, detectedLinks.size)
}
}
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.quartz.utils.urldetector
import com.vitorpamplona.quartz.utils.urldetector.detection.UrlDetector
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
/**
* Regression tests for PR #1907: StringIndexOutOfBoundsException in [Url.getPart] when
* processing the Japanese text "今北産業".
*/
class UrlTest {
/**
* Regression: detecting URLs in "今北産業" must not throw and must return no URLs.
*/
@Test
fun detectingImakitaSangyoDoesNotThrow() {
val urls = UrlDetector("今北産業").detect()
assertEquals(0, urls.size)
}
/**
* Regression: constructing a Url with "今北産業" as the original string and a HOST
* marker at 0 with PORT at the string length (simulating a trimmed trailing character)
* must not throw StringIndexOutOfBoundsException when accessing any property.
*
* "今北産業" has length 4. PORT at 4 == length triggers the startIndex >= length guard
* added to getPart() in PR #1907.
*/
@Test
fun urlPropertiesDoNotThrowForImakitaSangyoWithOutOfRangeMarker() {
val marker = UrlMarker()
marker.setIndex(UrlPart.HOST, 0)
marker.setIndex(UrlPart.PORT, 4) // == "今北産業".length
val url = marker.createUrl("今北産業")
assertNotNull(url.scheme)
assertNotNull(url.host)
assertNotNull(url.path)
assertNotNull(url.query)
assertNotNull(url.fragment)
assertEquals(-1, url.port) // getPart(PORT) returns null → -1
}
}