From 9565b17d5d743d7ae4028d484b407d649210f6d2 Mon Sep 17 00:00:00 2001
From: Eugen Rochko
Date: Thu, 24 Mar 2022 11:23:46 +0100
Subject: New Crowdin updates (#17829)
* New translations en.json (Kurmanji (Kurdish))
* New translations doorkeeper.en.yml (Kurmanji (Kurdish))
* New translations en.yml (Kurmanji (Kurdish))
* New translations en.yml (Kurmanji (Kurdish))
* New translations simple_form.en.yml (Kurmanji (Kurdish))
* New translations en.yml (Thai)
* New translations en.yml (Thai)
* New translations en.yml (Thai)
* New translations en.yml (Thai)
* New translations en.json (Japanese)
* New translations en.json (Japanese)
* New translations doorkeeper.en.yml (Indonesian)
* New translations en.json (Persian)
* New translations en.json (Persian)
* New translations en.json (Persian)
* New translations en.json (Persian)
* New translations en.json (Persian)
* New translations en.json (Persian)
* New translations en.json (Persian)
* New translations en.json (Persian)
* New translations en.json (Persian)
* New translations en.json (Persian)
* New translations en.json (Persian)
* New translations en.json (Persian)
* New translations en.json (Persian)
* New translations en.yml (Thai)
* New translations en.yml (Thai)
* New translations en.yml (Korean)
* New translations en.yml (Portuguese)
* New translations en.yml (Hungarian)
* New translations en.yml (Armenian)
* New translations en.yml (Georgian)
* New translations en.yml (Lithuanian)
* New translations en.yml (Macedonian)
* New translations en.yml (Dutch)
* New translations en.yml (Norwegian)
* New translations en.yml (Punjabi)
* New translations en.yml (Polish)
* New translations en.yml (Albanian)
* New translations en.yml (Basque)
* New translations en.yml (Serbian (Cyrillic))
* New translations en.yml (Turkish)
* New translations en.yml (Ukrainian)
* New translations en.yml (Chinese Traditional)
* New translations en.yml (Urdu (Pakistan))
* New translations en.yml (Icelandic)
* New translations en.yml (Portuguese, Brazilian)
* New translations en.yml (Indonesian)
* New translations en.yml (Tamil)
* New translations en.yml (Spanish, Argentina)
* New translations en.yml (Finnish)
* New translations en.yml (Greek)
* New translations en.yml (Galician)
* New translations en.yml (Slovak)
* New translations en.yml (Chinese Simplified)
* New translations en.yml (Swedish)
* New translations en.yml (Arabic)
* New translations en.yml (French)
* New translations en.yml (Spanish)
* New translations en.yml (Catalan)
* New translations en.yml (Hebrew)
* New translations en.yml (Italian)
* New translations en.yml (Japanese)
* New translations en.yml (Russian)
* New translations en.yml (Slovenian)
* New translations en.yml (German)
* New translations en.yml (Vietnamese)
* New translations en.yml (Persian)
* New translations en.yml (Romanian)
* New translations en.yml (Afrikaans)
* New translations en.yml (Bulgarian)
* New translations en.yml (Czech)
* New translations en.yml (Danish)
* New translations en.yml (Spanish, Mexico)
* New translations en.yml (Scottish Gaelic)
* New translations en.yml (Occitan)
* New translations en.yml (Bengali)
* New translations en.yml (Marathi)
* New translations en.yml (Silesian)
* New translations en.yml (Taigi)
* New translations en.yml (Ido)
* New translations en.yml (Kabyle)
* New translations en.yml (Sanskrit)
* New translations en.yml (Sardinian)
* New translations en.yml (Corsican)
* New translations en.yml (Sorani (Kurdish))
* New translations en.yml (Serbian (Latin))
* New translations en.yml (Asturian)
* New translations en.yml (Kannada)
* New translations en.yml (Cornish)
* New translations en.yml (Sinhala)
* New translations en.yml (Breton)
* New translations en.yml (Malayalam)
* New translations en.yml (Tatar)
* New translations en.yml (Chinese Traditional, Hong Kong)
* New translations en.yml (Uyghur)
* New translations en.yml (Esperanto)
* New translations en.yml (Welsh)
* New translations en.yml (Telugu)
* New translations en.yml (Malay)
* New translations en.yml (Hindi)
* New translations en.yml (Latvian)
* New translations en.yml (Estonian)
* New translations en.yml (Kazakh)
* New translations en.yml (Norwegian Nynorsk)
* New translations en.yml (Croatian)
* New translations en.yml (Standard Moroccan Tamazight)
* New translations en.yml (Catalan)
* New translations en.yml (Chinese Traditional)
* New translations en.yml (Latvian)
* New translations en.yml (Icelandic)
* New translations en.yml (Swedish)
* New translations en.yml (Thai)
* New translations en.yml (Portuguese)
* New translations en.yml (Thai)
* New translations en.yml (Russian)
* New translations en.yml (Russian)
* New translations en.yml (Thai)
* New translations en.yml (Danish)
* New translations en.yml (Spanish)
* New translations en.yml (Spanish, Argentina)
* New translations en.json (Japanese)
* New translations en.yml (German)
* New translations en.yml (Hungarian)
* New translations en.yml (Italian)
* New translations en.yml (Kurmanji (Kurdish))
* New translations en.yml (Chinese Simplified)
* New translations en.yml (Indonesian)
* New translations en.yml (Turkish)
* New translations en.json (Persian)
* New translations simple_form.en.yml (Persian)
* New translations en.yml (Thai)
* New translations simple_form.en.yml (Thai)
* New translations simple_form.en.yml (Persian)
* New translations simple_form.en.yml (Persian)
* New translations en.yml (Thai)
* New translations en.json (Dutch)
* New translations en.json (Dutch)
* New translations en.yml (Dutch)
* New translations en.json (Dutch)
* New translations en.yml (Dutch)
* New translations en.json (Dutch)
* New translations simple_form.en.yml (Dutch)
* New translations en.json (Dutch)
* New translations en.json (Dutch)
* New translations en.json (Dutch)
* New translations doorkeeper.en.yml (Dutch)
* New translations doorkeeper.en.yml (Dutch)
* New translations en.json (Dutch)
* New translations doorkeeper.en.yml (Dutch)
* New translations en.json (Dutch)
* New translations en.json (Dutch)
* New translations en.yml (Dutch)
* New translations en.json (Dutch)
* New translations en.yml (Dutch)
* New translations simple_form.en.yml (Dutch)
* New translations simple_form.en.yml (Dutch)
* New translations doorkeeper.en.yml (Dutch)
* New translations activerecord.en.yml (Dutch)
* New translations en.yml (Dutch)
* New translations doorkeeper.en.yml (Dutch)
* New translations en.yml (Korean)
* New translations en.yml (Galician)
* Run `bundle exec i18n-tasks normalize`
* Run `yarn manage:translations`
Co-authored-by: Yamagishi Kazutoshi
---
app/javascript/mastodon/locales/fa.json | 142 ++++++++++-----------
app/javascript/mastodon/locales/ja.json | 2 +-
app/javascript/mastodon/locales/ku.json | 4 +-
app/javascript/mastodon/locales/nl.json | 212 ++++++++++++++++----------------
4 files changed, 180 insertions(+), 180 deletions(-)
(limited to 'app')
diff --git a/app/javascript/mastodon/locales/fa.json b/app/javascript/mastodon/locales/fa.json
index 820b90640..d5276039d 100644
--- a/app/javascript/mastodon/locales/fa.json
+++ b/app/javascript/mastodon/locales/fa.json
@@ -3,16 +3,16 @@
"account.add_or_remove_from_list": "افزودن یا برداشتن از سیاههها",
"account.badges.bot": "روبات",
"account.badges.group": "گروه",
- "account.block": "مسدود کردن @{name}",
+ "account.block": "مسدود کردن @{name}",
"account.block_domain": "مسدود کردن دامنهٔ {domain}",
"account.blocked": "مسدود",
"account.browse_more_on_origin_server": "مرور بیشتر روی نمایهٔ اصلی",
"account.cancel_follow_request": "لغو درخواست پیگیری",
- "account.direct": "پیام مستقیم به @{name}",
- "account.disable_notifications": "آگاهی به من هنگام فرستادنهای @{name} پایان یابد",
+ "account.direct": "پیام مستقیم به @{name}",
+ "account.disable_notifications": "آگاهی به من هنگام فرستادنهای @{name} پایان یابد",
"account.domain_blocked": "دامنه مسدود شد",
"account.edit_profile": "ویرایش نمایه",
- "account.enable_notifications": "هنگام فرستههای @{name} مرا آگاه کن",
+ "account.enable_notifications": "هنگام فرستههای @{name} مرا آگاه کن",
"account.endorse": "معرّفی در نمایه",
"account.follow": "پیگیری",
"account.followers": "پیگیرندگان",
@@ -22,34 +22,34 @@
"account.following_counter": "{count, plural, one {{counter} پیگرفته} other {{counter} پیگرفته}}",
"account.follows.empty": "این کاربر هنوز پیگیر کسی نیست.",
"account.follows_you": "پی میگیردتان",
- "account.hide_reblogs": "نهفتن تقویتهای @{name}",
+ "account.hide_reblogs": "نهفتن تقویتهای @{name}",
"account.joined": "پیوسته از {date}",
"account.link_verified_on": "مالکیت این پیوند در {date} بررسی شد",
"account.locked_info": "این حساب خصوصی است. صاحبش تصمیم میگیرد که چه کسی پیگیرش باشد.",
"account.media": "رسانه",
- "account.mention": "نامبردن از @{name}",
+ "account.mention": "نامبردن از @{name}",
"account.moved_to": "{name} منتقل شده به:",
- "account.mute": "خموشاندن @{name}",
- "account.mute_notifications": "خموشاندن آگاهیها از @{name}",
+ "account.mute": "خموشاندن @{name}",
+ "account.mute_notifications": "خموشاندن آگاهیهای @{name}",
"account.muted": "خموش",
"account.posts": "فرسته",
"account.posts_with_replies": "فرستهها و پاسخها",
- "account.report": "گزارش @{name}",
+ "account.report": "گزارش @{name}",
"account.requested": "منتظر پذیرش است. برای لغو درخواست پیگیری کلیک کنید",
- "account.share": "همرسانی نمایهٔ @{name}",
- "account.show_reblogs": "نمایش تقویتهای @{name}",
+ "account.share": "همرسانی نمایهٔ @{name}",
+ "account.show_reblogs": "نمایش تقویتهای @{name}",
"account.statuses_counter": "{count, plural, one {{counter} فرسته} other {{counter} فرسته}}",
- "account.unblock": "رفع مسدودیت @{name}",
+ "account.unblock": "رفع مسدودیت @{name}",
"account.unblock_domain": "رفع مسدودیت دامنهٔ {domain}",
"account.unblock_short": "رفع مسدودیت",
"account.unendorse": "معرّفی نکردن در نمایه",
"account.unfollow": "ناپیگیری",
- "account.unmute": "ناخموشی @{name}",
- "account.unmute_notifications": "ناخموشی آگاهیها از @{name}",
+ "account.unmute": "ناخموشی @{name}",
+ "account.unmute_notifications": "ناخموشی آگاهیهای @{name}",
"account.unmute_short": "ناخموشی",
"account_note.placeholder": "برای افزودن یادداشت کلیک کنید",
- "admin.dashboard.daily_retention": "User retention rate by day after sign-up",
- "admin.dashboard.monthly_retention": "User retention rate by month after sign-up",
+ "admin.dashboard.daily_retention": "نرخ حفظ کاربر در روز پس از ثبت نام",
+ "admin.dashboard.monthly_retention": "نرخ حفظ کاربر در ماه پس از ثبت نام",
"admin.dashboard.retention.average": "میانگین",
"admin.dashboard.retention.cohort": "ماه ثبتنام",
"admin.dashboard.retention.cohort_size": "کاربران جدید",
@@ -79,13 +79,13 @@
"column.lists": "سیاههها",
"column.mutes": "کاربران خموش",
"column.notifications": "آگاهیها",
- "column.pins": "فرستههای سنجاقشده",
+ "column.pins": "فرستههای سنجاق شده",
"column.public": "خط زمانی همگانی",
"column_back_button.label": "بازگشت",
"column_header.hide_settings": "نهفتن تنظیمات",
"column_header.moveLeft_settings": "جابهجایی ستون به چپ",
"column_header.moveRight_settings": "جابهجایی ستون به راست",
- "column_header.pin": "سنجاقکردن",
+ "column_header.pin": "سنجاق کردن",
"column_header.show_settings": "نمایش تنظیمات",
"column_header.unpin": "برداشتن سنجاق",
"column_subheading.settings": "تنظیمات",
@@ -94,7 +94,7 @@
"community.column_settings.remote_only": "تنها دوردست",
"compose_form.direct_message_warning": "این فرسته تنها به کاربرانی که از آنها نام برده شده فرستاده خواهد شد.",
"compose_form.direct_message_warning_learn_more": "بیشتر بدانید",
- "compose_form.hashtag_warning": "از آنجا که این فرسته فهرستنشده است، در نتایج جستوجوی برچسبها پیدا نخواهد شد. تنها فرستههای عمومی را میتوان با جستوجوی برچسب یافت.",
+ "compose_form.hashtag_warning": "از آنجا که این فرسته فهرست نشده است، در نتایج جستوجوی هشتگها پیدا نخواهد شد. تنها فرستههای عمومی را میتوان با جستوجوی هشتگ یافت.",
"compose_form.lock_disclaimer": "حسابتان {locked} نیست. هر کسی میتواند پیگیرتان شده و فرستههای ویژهٔ پیگیرانتان را ببیند.",
"compose_form.lock_disclaimer.lock": "قفلشده",
"compose_form.placeholder": "تازه چه خبر؟",
@@ -144,7 +144,7 @@
"directory.local": "تنها از {domain}",
"directory.new_arrivals": "تازهواردان",
"directory.recently_active": "کاربران فعال اخیر",
- "embed.instructions": "برای جاگذاری این فرسته در سایت خودتان، کد زیر را کپی کنید.",
+ "embed.instructions": "برای جاسازی این فرسته در سایت خودتان، کد زیر را رونوشت کنید.",
"embed.preview": "این گونه دیده خواهد شد:",
"emoji_button.activity": "فعالیت",
"emoji_button.custom": "سفارشی",
@@ -164,11 +164,11 @@
"empty_column.account_timeline": "هیچ فرستهای اینجا نیست!",
"empty_column.account_unavailable": "نمایهٔ موجود نیست",
"empty_column.blocks": "هنوز کسی را مسدود نکردهاید.",
- "empty_column.bookmarked_statuses": "هنوز هیچ فرستهٔ نشانشدهای ندارید. هنگامی که فرستهای را نشانکنید، اینجا نشان داده خواهد شد.",
+ "empty_column.bookmarked_statuses": "هنوز هیچ فرستهٔ نشانهگذاری شدهای ندارید. هنگامی که فرستهای را نشانهگذاری کنید، اینجا نشان داده خواهد شد.",
"empty_column.community": "خط زمانی محلّی خالی است. چیزی بنویسید تا چرخش بچرخد!",
"empty_column.direct": "هنوز هیچ پیام مستقیمی ندارید. هنگامی که چنین پیامی بگیرید یا بفرستید اینجا نشان داده خواهد شد.",
"empty_column.domain_blocks": "هنوز هیچ دامنهای مسدود نشده است.",
- "empty_column.explore_statuses": "Nothing is trending right now. Check back later!",
+ "empty_column.explore_statuses": "الآن چیزی پرطرفدار نیست. بعداً دوباره بررسی کنید!",
"empty_column.favourited_statuses": "شما هنوز هیچ فرستهای را نپسندیدهاید. هنگامی که فرستهای را بپسندید، اینجا نشان داده خواهد شد.",
"empty_column.favourites": "هنوز هیچ کسی این فرسته را نپسندیده است. هنگامی که کسی آن را بپسندد، اینجا نشان داده خواهد شد.",
"empty_column.follow_recommendations": "ظاهرا هیچ پیشنهادی برای شما نمیتوانیم تولید کنیم. میتوانید از امکان جستوجو برای یافتن افرادی که ممکن است بشناسید و یا کاوش میان برچسبهای داغ استفاده کنید.",
@@ -247,7 +247,7 @@
"keyboard_shortcuts.my_profile": "گشودن نمایهتان",
"keyboard_shortcuts.notifications": "گشودن ستون آگاهیها",
"keyboard_shortcuts.open_media": "گشودن رسانه",
- "keyboard_shortcuts.pinned": "گشودن سیاههٔ فرستههای سنجاق شده",
+ "keyboard_shortcuts.pinned": "گشودن فهرست فرستههای سنجاق شده",
"keyboard_shortcuts.profile": "گشودن نمایهٔ نویسنده",
"keyboard_shortcuts.reply": "پاسخ به فرسته",
"keyboard_shortcuts.requests": "گشودن سیاههٔ درخواستهای پیگیری",
@@ -305,7 +305,7 @@
"navigation_bar.logout": "خروج",
"navigation_bar.mutes": "کاربران خموشانده",
"navigation_bar.personal": "شخصی",
- "navigation_bar.pins": "فرستههای سنجاقشده",
+ "navigation_bar.pins": "فرستههای سنجاق شده",
"navigation_bar.preferences": "ترجیحات",
"navigation_bar.public_timeline": "خط زمانی همگانی",
"navigation_bar.security": "امنیت",
@@ -392,40 +392,40 @@
"report.block": "مسدود کردن",
"report.block_explanation": "شما فرستههایشان را نخواهید دید. آنها نمیتوانند فرستههایتان را ببینند یا شما را پیبگیرند. آنها میتوانند بگویند که مسدود شدهاند.",
"report.categories.other": "غیره",
- "report.categories.spam": "Spam",
- "report.categories.violation": "Content violates one or more server rules",
- "report.category.subtitle": "Choose the best match",
- "report.category.title": "Tell us what's going on with this {type}",
- "report.category.title_account": "profile",
- "report.category.title_status": "post",
- "report.close": "Done",
- "report.comment.title": "Is there anything else you think we should know?",
+ "report.categories.spam": "هرزنامه",
+ "report.categories.violation": "محتوا یک یا چند قانون کارساز را نقض میکند",
+ "report.category.subtitle": "منطبقترین را انتخاب کنید",
+ "report.category.title": "به ما بگویید با این {type} چه مشکلی دارید",
+ "report.category.title_account": "نمایه",
+ "report.category.title_status": "فرسته",
+ "report.close": "انجام شد",
+ "report.comment.title": "آیا چیز دیگری هست که فکر میکنید باید بدانیم؟",
"report.forward": "فرستادن به {target}",
"report.forward_hint": "این حساب در کارساز دیگری ثبت شده. آیا میخواهید رونوشتی ناشناس از این گزارش به آنجا هم فرستاده شود؟",
- "report.mute": "Mute",
- "report.mute_explanation": "You will not see their posts. They can still follow you and see your posts and will not know that they are muted.",
- "report.next": "Next",
+ "report.mute": "خموش",
+ "report.mute_explanation": "شما فرستههای آنها را نخواهید دید. آنها همچنان میتوانند شما را پیبگیرند و فرستههایتان را ببینند و نمیدانند که خموش شدهاند.",
+ "report.next": "بعدی",
"report.placeholder": "توضیحات اضافه",
- "report.reasons.dislike": "I don't like it",
- "report.reasons.dislike_description": "It is not something you want to see",
- "report.reasons.other": "It's something else",
- "report.reasons.other_description": "The issue does not fit into other categories",
- "report.reasons.spam": "It's spam",
- "report.reasons.spam_description": "Malicious links, fake engagement, or repetitive replies",
- "report.reasons.violation": "It violates server rules",
- "report.reasons.violation_description": "You are aware that it breaks specific rules",
- "report.rules.subtitle": "Select all that apply",
- "report.rules.title": "Which rules are being violated?",
- "report.statuses.subtitle": "Select all that apply",
- "report.statuses.title": "Are there any posts that back up this report?",
+ "report.reasons.dislike": "من آن را دوست ندارم",
+ "report.reasons.dislike_description": "این چیزی نیست که بخواهید ببینید",
+ "report.reasons.other": "بخواطر چیز دیگری است",
+ "report.reasons.other_description": "این موضوع در دستهبندیهای دیگر نمیگنجد",
+ "report.reasons.spam": "این هرزنامه است",
+ "report.reasons.spam_description": "پیوندهای مخرب، تعامل جعلی یا پاسخهای تکراری",
+ "report.reasons.violation": "قوانین کارساز را نقض میکند",
+ "report.reasons.violation_description": "شما آگاه هستید که قوانین خاصی را زیر پا میگذارد",
+ "report.rules.subtitle": "همهٔ موارد انجام شده را برگزینید",
+ "report.rules.title": "کدام قوانین نقض شدهاند؟",
+ "report.statuses.subtitle": "همهٔ موارد انجام شده را برگزینید",
+ "report.statuses.title": "آیا فرستهای وجود دارد که از این گزارش پشتیبانی کند؟",
"report.submit": "فرستادن",
"report.target": "در حال گزارش {target}",
- "report.thanks.take_action": "Here are your options for controlling what you see on Mastodon:",
- "report.thanks.take_action_actionable": "While we review this, you can take action against @{name}:",
- "report.thanks.title": "Don't want to see this?",
- "report.thanks.title_actionable": "Thanks for reporting, we'll look into this.",
- "report.unfollow": "Unfollow @{name}",
- "report.unfollow_explanation": "You are following this account. To not see their posts in your home feed anymore, unfollow them.",
+ "report.thanks.take_action": "در اینجا گزینههایی برای کنترل آنچه در ماستودون میبینید، وجود دارد:",
+ "report.thanks.take_action_actionable": "در حالی که ما این مورد را بررسی میکنیم، میتوانید علیه @{name} اقدام کنید:",
+ "report.thanks.title": "نمیخواهید این را ببینید؟",
+ "report.thanks.title_actionable": "ممنون بابت گزارش، ما آن را بررسی خواهیم کرد.",
+ "report.unfollow": "ناپیگیری @{name}",
+ "report.unfollow_explanation": "شما این حساب را پیگرفتهاید، برای اینکه دیگر فرستههایش را در خوراک خانهتان نبینید؛ آن را پینگیرید.",
"search.placeholder": "جستوجو",
"search_popout.search_format": "راهنمای جستوجوی پیشرفته",
"search_popout.tips.full_text": "جستوجوی متنی ساده فرستههایی که نوشته، پسندیده، تقویتکرده یا در آنها نامبرده شدهاید را به علاوهٔ نامهای کاربری، نامهای نمایشی و برچسبها برمیگرداند.",
@@ -434,39 +434,39 @@
"search_popout.tips.text": "جستوجوی متنی ساده برای نامها، نامهای کاربری، و برچسبها",
"search_popout.tips.user": "کاربر",
"search_results.accounts": "افراد",
- "search_results.all": "All",
+ "search_results.all": "همه",
"search_results.hashtags": "برچسبها",
- "search_results.nothing_found": "Could not find anything for these search terms",
+ "search_results.nothing_found": "چیزی برای این عبارت جستوجو یافت نشد",
"search_results.statuses": "فرستهها",
- "search_results.statuses_fts_disabled": "جستوجوی محتوای فرستهها در این کارساز ماستودون فعال نشده است.",
+ "search_results.statuses_fts_disabled": "جستوجوی محتوای فرستهها در این کارساز ماستودون به کار انداخته نشده است.",
"search_results.total": "{count, number} {count, plural, one {نتیجه} other {نتیجه}}",
- "status.admin_account": "گشودن واسط مدیریت برای @{name}",
+ "status.admin_account": "گشودن واسط مدیریت برای @{name}",
"status.admin_status": "گشودن این فرسته در واسط مدیریت",
- "status.block": "مسدود کردن @{name}",
+ "status.block": "مسدود کردن @{name}",
"status.bookmark": "نشانک",
"status.cancel_reblog_private": "لغو تقویت",
"status.cannot_reblog": "این فرسته قابل تقویت نیست",
- "status.copy": "رونویسی از نشانی فرسته",
+ "status.copy": "رونوشت پیوند فرسته",
"status.delete": "حذف",
"status.detailed_status": "نمایش کامل گفتگو",
- "status.direct": "پیام مستقیم به @{name}",
- "status.edit": "Edit",
- "status.edited": "Edited {date}",
- "status.edited_x_times": "Edited {count, plural, one {{count} time} other {{count} times}}",
- "status.embed": "جاگذاری",
+ "status.direct": "پیام مستقیم به @{name}",
+ "status.edit": "ویرایش",
+ "status.edited": "ویرایش شده در {date}",
+ "status.edited_x_times": "{count, plural, one {{count} مرتبه} other {{count} مرتبه}} ویرایش شد",
+ "status.embed": "جاسازی",
"status.favourite": "پسندیدن",
"status.filtered": "پالوده",
- "status.history.created": "{name} created {date}",
- "status.history.edited": "{name} edited {date}",
+ "status.history.created": "توسط {name} در {date} ایجاد شد",
+ "status.history.edited": "توسط {name} در {date} ویرایش شد",
"status.load_more": "بار کردن بیشتر",
"status.media_hidden": "رسانهٔ نهفته",
- "status.mention": "نامبردن از @{name}",
+ "status.mention": "نامبردن از @{name}",
"status.more": "بیشتر",
- "status.mute": "خموشاندن @{name}",
+ "status.mute": "خموشاندن @{name}",
"status.mute_conversation": "خموشاندن گفتوگو",
"status.open": "گسترش این فرسته",
- "status.pin": "سنجاقکردن در نمایه",
- "status.pinned": "فرستهٔ سنجاقشده",
+ "status.pin": "سنجاق کردن در نمایه",
+ "status.pinned": "فرستهٔ سنجاق شده",
"status.read_more": "بیشتر بخوانید",
"status.reblog": "تقویت",
"status.reblog_private": "تقویت برای مخاطبان نخستین",
@@ -476,7 +476,7 @@
"status.remove_bookmark": "برداشتن نشانک",
"status.reply": "پاسخ",
"status.replyAll": "پاسخ به رشته",
- "status.report": "گزارش @{name}",
+ "status.report": "گزارش @{name}",
"status.sensitive_warning": "محتوای حساس",
"status.share": "همرسانی",
"status.show_less": "نمایش کمتر",
diff --git a/app/javascript/mastodon/locales/ja.json b/app/javascript/mastodon/locales/ja.json
index 8c7878a84..b5257e80d 100644
--- a/app/javascript/mastodon/locales/ja.json
+++ b/app/javascript/mastodon/locales/ja.json
@@ -188,7 +188,7 @@
"errors.unexpected_crash.copy_stacktrace": "スタックトレースをクリップボードにコピー",
"errors.unexpected_crash.report_issue": "問題を報告",
"explore.search_results": "検索結果",
- "explore.suggested_follows": "あなたに",
+ "explore.suggested_follows": "おすすめ",
"explore.title": "エクスプローラー",
"explore.trending_links": "ニュース",
"explore.trending_statuses": "投稿",
diff --git a/app/javascript/mastodon/locales/ku.json b/app/javascript/mastodon/locales/ku.json
index 0298c51ec..2bf8fc520 100644
--- a/app/javascript/mastodon/locales/ku.json
+++ b/app/javascript/mastodon/locales/ku.json
@@ -342,7 +342,7 @@
"notifications.filter.all": "Hemû",
"notifications.filter.boosts": "Bilindkirî",
"notifications.filter.favourites": "Bijarte",
- "notifications.filter.follows": "Şopîner",
+ "notifications.filter.follows": "Dişopîne",
"notifications.filter.mentions": "Qalkirin",
"notifications.filter.polls": "Encamên rapirsiyê",
"notifications.filter.statuses": "Ji kesên tu dişopînî re rojanekirin",
@@ -501,7 +501,7 @@
"time_remaining.seconds": "{number, plural, one {# çirke} other {# çirke}} maye",
"timeline_hint.remote_resource_not_displayed": "{resource} Ji rajekerên din nayê dîtin.",
"timeline_hint.resources.followers": "Şopîner",
- "timeline_hint.resources.follows": "Şopîner",
+ "timeline_hint.resources.follows": "Dişopîne",
"timeline_hint.resources.statuses": "Şandiyên kevn",
"trends.counter_by_accounts": "{count, plural, one {{counter} kes} other {{counter} kes}} diaxivin",
"trends.trending_now": "Rojev",
diff --git a/app/javascript/mastodon/locales/nl.json b/app/javascript/mastodon/locales/nl.json
index f30755286..d1cfdd5f4 100644
--- a/app/javascript/mastodon/locales/nl.json
+++ b/app/javascript/mastodon/locales/nl.json
@@ -9,44 +9,44 @@
"account.browse_more_on_origin_server": "Meer op het originele profiel bekijken",
"account.cancel_follow_request": "Volgverzoek annuleren",
"account.direct": "@{name} een direct bericht sturen",
- "account.disable_notifications": "Geef geen melding meer wanneer @{name} toot",
+ "account.disable_notifications": "Geef geen melding meer wanneer @{name} een bericht plaatst",
"account.domain_blocked": "Domein geblokkeerd",
"account.edit_profile": "Profiel bewerken",
- "account.enable_notifications": "Geef een melding wanneer @{name} toot",
+ "account.enable_notifications": "Geef een melding wanneer @{name} een bericht plaatst",
"account.endorse": "Op profiel weergeven",
"account.follow": "Volgen",
"account.followers": "Volgers",
"account.followers.empty": "Niemand volgt nog deze gebruiker.",
"account.followers_counter": "{count, plural, one {{counter} volger} other {{counter} volgers}}",
- "account.following": "Following",
+ "account.following": "Volgend",
"account.following_counter": "{count, plural, one {{counter} volgend} other {{counter} volgend}}",
"account.follows.empty": "Deze gebruiker volgt nog niemand.",
"account.follows_you": "Volgt jou",
"account.hide_reblogs": "Boosts van @{name} verbergen",
"account.joined": "Geregistreerd in {date}",
"account.link_verified_on": "Eigendom van deze link is gecontroleerd op {date}",
- "account.locked_info": "De privacystatus van dit account is op besloten gezet. De eigenaar bepaalt handmatig wie hen kan volgen.",
+ "account.locked_info": "De privacystatus van dit account is op besloten gezet. De eigenaar bepaalt handmatig wie diegene kan volgen.",
"account.media": "Media",
"account.mention": "@{name} vermelden",
"account.moved_to": "{name} is verhuisd naar:",
"account.mute": "@{name} negeren",
"account.mute_notifications": "Meldingen van @{name} negeren",
"account.muted": "Genegeerd",
- "account.posts": "Toots",
- "account.posts_with_replies": "Toots en reacties",
+ "account.posts": "Berichten",
+ "account.posts_with_replies": "Berichten en reacties",
"account.report": "@{name} rapporteren",
"account.requested": "Wacht op goedkeuring. Klik om het volgverzoek te annuleren",
"account.share": "Profiel van @{name} delen",
"account.show_reblogs": "Boosts van @{name} tonen",
- "account.statuses_counter": "{count, plural, one {{counter} toot} other {{counter} toots}}",
+ "account.statuses_counter": "{count, plural, one {{counter} bericht} other {{counter} berichten}}",
"account.unblock": "@{name} deblokkeren",
"account.unblock_domain": "{domain} niet langer verbergen",
- "account.unblock_short": "Unblock",
+ "account.unblock_short": "Deblokkeren",
"account.unendorse": "Niet op profiel weergeven",
"account.unfollow": "Ontvolgen",
"account.unmute": "@{name} niet langer negeren",
"account.unmute_notifications": "Meldingen van @{name} niet langer negeren",
- "account.unmute_short": "Unmute",
+ "account.unmute_short": "Niet langer negeren",
"account_note.placeholder": "Klik om een opmerking toe te voegen",
"admin.dashboard.daily_retention": "User retention rate by day after sign-up",
"admin.dashboard.monthly_retention": "User retention rate by month after sign-up",
@@ -79,7 +79,7 @@
"column.lists": "Lijsten",
"column.mutes": "Genegeerde gebruikers",
"column.notifications": "Meldingen",
- "column.pins": "Vastgezette toots",
+ "column.pins": "Vastgezette berichten",
"column.public": "Globale tijdlijn",
"column_back_button.label": "Terug",
"column_header.hide_settings": "Instellingen verbergen",
@@ -92,10 +92,10 @@
"community.column_settings.local_only": "Alleen lokaal",
"community.column_settings.media_only": "Alleen media",
"community.column_settings.remote_only": "Alleen andere servers",
- "compose_form.direct_message_warning": "Deze toot wordt alleen naar vermelde gebruikers verstuurd.",
+ "compose_form.direct_message_warning": "Dit bericht wordt alleen naar vermelde gebruikers verstuurd.",
"compose_form.direct_message_warning_learn_more": "Meer leren",
- "compose_form.hashtag_warning": "Deze toot valt niet onder een hashtag te bekijken, omdat deze niet op openbare tijdlijnen wordt getoond. Alleen openbare toots kunnen via hashtags gevonden worden.",
- "compose_form.lock_disclaimer": "Jouw account is niet {locked}. Iedereen kan jou volgen en kan de toots zien die je alleen aan jouw volgers hebt gericht.",
+ "compose_form.hashtag_warning": "Dit bericht valt niet onder een hashtag te bekijken, omdat deze niet op openbare tijdlijnen wordt getoond. Alleen openbare berichten kunnen via hashtags gevonden worden.",
+ "compose_form.lock_disclaimer": "Jouw account is niet {locked}. Iedereen kan jou volgen en kan de berichten zien die je alleen aan jouw volgers hebt gericht.",
"compose_form.lock_disclaimer.lock": "besloten",
"compose_form.placeholder": "Wat wil je kwijt?",
"compose_form.poll.add_option": "Keuze toevoegen",
@@ -106,7 +106,7 @@
"compose_form.poll.switch_to_single": "Poll wijzigen om een enkele keuze toe te staan",
"compose_form.publish": "Toot",
"compose_form.publish_loud": "{publish}!",
- "compose_form.save_changes": "Save changes",
+ "compose_form.save_changes": "Wijzigingen opslaan",
"compose_form.sensitive.hide": "{count, plural, one {Media als gevoelig markeren} other {Media als gevoelig markeren}}",
"compose_form.sensitive.marked": "{count, plural, one {Media is als gevoelig gemarkeerd} other {Media is als gevoelig gemarkeerd}}",
"compose_form.sensitive.unmarked": "{count, plural, one {Media is niet als gevoelig gemarkeerd} other {Media is niet als gevoelig gemarkeerd}}",
@@ -118,22 +118,22 @@
"confirmations.block.confirm": "Blokkeren",
"confirmations.block.message": "Weet je het zeker dat je {name} wilt blokkeren?",
"confirmations.delete.confirm": "Verwijderen",
- "confirmations.delete.message": "Weet je het zeker dat je deze toot wilt verwijderen?",
+ "confirmations.delete.message": "Weet je het zeker dat je dit bericht wilt verwijderen?",
"confirmations.delete_list.confirm": "Verwijderen",
"confirmations.delete_list.message": "Weet je zeker dat je deze lijst definitief wilt verwijderen?",
"confirmations.discard_edit_media.confirm": "Weggooien",
"confirmations.discard_edit_media.message": "Je hebt niet-opgeslagen wijzigingen in de mediabeschrijving of voorvertonning, wil je deze toch weggooien?",
"confirmations.domain_block.confirm": "Verberg alles van deze server",
- "confirmations.domain_block.message": "Weet je het echt heel erg zeker dat je alles van {domain} wilt negeren? In de meeste gevallen is het blokkeren of negeren van een paar specifieke personen voldoende en beter. Je zult geen toots van deze server op openbare tijdlijnen zien of in jouw meldingen. Jouw volgers van deze server worden verwijderd.",
+ "confirmations.domain_block.message": "Weet je het echt heel erg zeker dat je alles van {domain} wilt negeren? In de meeste gevallen is het blokkeren of negeren van een paar specifieke personen voldoende en beter. Je zult geen berichten van deze server op openbare tijdlijnen zien of in jouw meldingen. Jouw volgers van deze server worden verwijderd.",
"confirmations.logout.confirm": "Uitloggen",
"confirmations.logout.message": "Weet je zeker dat je wilt uitloggen?",
"confirmations.mute.confirm": "Negeren",
- "confirmations.mute.explanation": "Dit verbergt toots van hen en toots waar hen in wordt vermeld, maar hen kan nog steeds jouw toots bekijken en jou volgen.",
+ "confirmations.mute.explanation": "Dit verbergt diens berichten en berichten waar diegene in wordt vermeld, maar diegene kan nog steeds jouw berichten bekijken en jou volgen.",
"confirmations.mute.message": "Weet je het zeker dat je {name} wilt negeren?",
"confirmations.redraft.confirm": "Verwijderen en herschrijven",
- "confirmations.redraft.message": "Weet je zeker dat je deze toot wilt verwijderen en herschrijven? Je verliest wel de boosts en favorieten, en de reacties op de originele toot zitten niet meer aan de nieuwe toot vast.",
+ "confirmations.redraft.message": "Weet je zeker dat je dit bericht wilt verwijderen en herschrijven? Je verliest wel de boosts en favorieten, en de reacties op het originele bericht raak je kwijt.",
"confirmations.reply.confirm": "Reageren",
- "confirmations.reply.message": "Door nu te reageren overschrijf je de toot die je op dit moment aan het schrijven bent. Weet je zeker dat je verder wil gaan?",
+ "confirmations.reply.message": "Door nu te reageren overschrijf je het bericht dat je op dit moment aan het schrijven bent. Weet je zeker dat je verder wil gaan?",
"confirmations.unfollow.confirm": "Ontvolgen",
"confirmations.unfollow.message": "Weet je het zeker dat je {name} wilt ontvolgen?",
"conversation.delete": "Gesprek verwijderen",
@@ -144,7 +144,7 @@
"directory.local": "Alleen {domain}",
"directory.new_arrivals": "Nieuwe accounts",
"directory.recently_active": "Onlangs actief",
- "embed.instructions": "Embed deze toot op jouw website, door de onderstaande code te kopiëren.",
+ "embed.instructions": "Embed dit bericht op jouw website door de onderstaande code te kopiëren.",
"embed.preview": "Zo komt het eruit te zien:",
"emoji_button.activity": "Activiteiten",
"emoji_button.custom": "Lokale emoji’s",
@@ -161,41 +161,41 @@
"emoji_button.symbols": "Symbolen",
"emoji_button.travel": "Reizen en locaties",
"empty_column.account_suspended": "Account opgeschort",
- "empty_column.account_timeline": "Hier zijn geen toots!",
+ "empty_column.account_timeline": "Hier zijn geen berichten!",
"empty_column.account_unavailable": "Profiel is niet beschikbaar",
"empty_column.blocks": "Jij hebt nog geen enkele gebruiker geblokkeerd.",
- "empty_column.bookmarked_statuses": "Jij hebt nog geen toots aan je bladwijzers toegevoegd. Wanneer je er een aan jouw bladwijzers toevoegt, valt deze hier te zien.",
- "empty_column.community": "De lokale tijdlijn is nog leeg. Toot iets in het openbaar om de spits af te bijten!",
+ "empty_column.bookmarked_statuses": "Jij hebt nog geen berichten aan je bladwijzers toegevoegd. Wanneer je er een aan jouw bladwijzers toevoegt, valt deze hier te zien.",
+ "empty_column.community": "De lokale tijdlijn is nog leeg. Plaats een openbaar bericht om de spits af te bijten!",
"empty_column.direct": "Je hebt nog geen directe berichten. Wanneer je er een verzend of ontvangt, zijn deze hier te zien.",
"empty_column.domain_blocks": "Er zijn nog geen geblokkeerde domeinen.",
- "empty_column.explore_statuses": "Nothing is trending right now. Check back later!",
- "empty_column.favourited_statuses": "Jij hebt nog geen favoriete toots. Wanneer je er een aan jouw favorieten toevoegt, valt deze hier te zien.",
- "empty_column.favourites": "Niemand heeft deze toot nog aan hun favorieten toegevoegd. Wanneer iemand dit doet, valt dat hier te zien.",
+ "empty_column.explore_statuses": "Momenteel zijn er geen trends. Kom later terug!",
+ "empty_column.favourited_statuses": "Jij hebt nog geen favoriete berichten. Wanneer je er een aan jouw favorieten toevoegt, valt deze hier te zien.",
+ "empty_column.favourites": "Niemand heeft dit bericht nog aan diens favorieten toegevoegd. Wanneer iemand dit doet, valt dat hier te zien.",
"empty_column.follow_recommendations": "Het lijkt er op dat er geen aanbevelingen voor jou aangemaakt kunnen worden. Je kunt proberen te zoeken naar mensen die je wellicht kent, zoeken op hashtags, de lokale en globale tijdlijnen bekijken of de gebruikersgids doorbladeren.",
"empty_column.follow_requests": "Jij hebt nog enkel volgverzoek ontvangen. Wanneer je er eentje ontvangt, valt dat hier te zien.",
"empty_column.hashtag": "Er is nog niks te vinden onder deze hashtag.",
"empty_column.home": "Deze tijdlijn is leeg! Volg meer mensen om het te vullen. {suggestions}",
"empty_column.home.suggestions": "Enkele aanbevelingen bekijken",
- "empty_column.list": "Er is nog niks te zien in deze lijst. Wanneer lijstleden nieuwe toots publiceren, zijn deze hier te zien.",
+ "empty_column.list": "Er is nog niks te zien in deze lijst. Wanneer lijstleden nieuwe berichten plaatsen, zijn deze hier te zien.",
"empty_column.lists": "Jij hebt nog geen enkele lijst. Wanneer je er eentje hebt aangemaakt, valt deze hier te zien.",
"empty_column.mutes": "Jij hebt nog geen gebruikers genegeerd.",
"empty_column.notifications": "Je hebt nog geen meldingen. Begin met iemand een gesprek.",
- "empty_column.public": "Er is hier helemaal niks! Toot iets in het openbaar of volg mensen van andere servers om het te vullen",
+ "empty_column.public": "Er is hier helemaal niks! Plaatst een openbaar bericht of volg mensen van andere servers om het te vullen",
"error.unexpected_crash.explanation": "Als gevolg van een bug in onze broncode of als gevolg van een compatibiliteitsprobleem met jouw webbrowser, kan deze pagina niet goed worden weergegeven.",
"error.unexpected_crash.explanation_addons": "Deze pagina kon niet correct geladen worden. Deze fout wordt waarschijnlijk door een browser-add-on of een automatische vertalingshulpmiddel veroorzaakt.",
"error.unexpected_crash.next_steps": "Probeer deze pagina te vernieuwen. Wanneer dit niet helpt is het nog steeds mogelijk om Mastodon in een andere webbrowser of mobiele app te gebruiken.",
"error.unexpected_crash.next_steps_addons": "Probeer deze uit te schakelen en de pagina te verversen. Wanneer dat niet helpt, kun je Mastodon nog altijd met een andere webbrowser of mobiele app gebruiken.",
"errors.unexpected_crash.copy_stacktrace": "Stacktrace naar klembord kopiëren",
"errors.unexpected_crash.report_issue": "Technisch probleem melden",
- "explore.search_results": "Search results",
- "explore.suggested_follows": "For you",
- "explore.title": "Explore",
- "explore.trending_links": "News",
- "explore.trending_statuses": "Posts",
+ "explore.search_results": "Zoekresultaten",
+ "explore.suggested_follows": "Voor jou",
+ "explore.title": "Verkennen",
+ "explore.trending_links": "Nieuws",
+ "explore.trending_statuses": "Berichten",
"explore.trending_tags": "Hashtags",
"follow_recommendations.done": "Klaar",
- "follow_recommendations.heading": "Volg mensen waarvan je graag toots wil zien! Hier zijn enkele aanbevelingen.",
- "follow_recommendations.lead": "Toots van mensen die je volgt zullen in chronologische volgorde onder start verschijnen. Wees niet bang om hierin fouten te maken, want je kunt mensen op elk moment net zo eenvoudig ontvolgen!",
+ "follow_recommendations.heading": "Volg mensen waarvan je graag berichten wil zien! Hier zijn enkele aanbevelingen.",
+ "follow_recommendations.lead": "Berichten van mensen die je volgt zullen in chronologische volgorde onder start verschijnen. Wees niet bang om hierin fouten te maken, want je kunt mensen op elk moment net zo eenvoudig ontvolgen!",
"follow_request.authorize": "Goedkeuren",
"follow_request.reject": "Afkeuren",
"follow_requests.unlocked_explanation": "Ook al is jouw account niet besloten, de medewerkers van {domain} denken dat jij misschien de volgende volgverzoeken handmatig wil controleren.",
@@ -227,13 +227,13 @@
"intervals.full.minutes": "{number, plural, one {# minuut} other {# minuten}}",
"keyboard_shortcuts.back": "Ga terug",
"keyboard_shortcuts.blocked": "Geblokkeerde gebruikers tonen",
- "keyboard_shortcuts.boost": "Toot boosten",
+ "keyboard_shortcuts.boost": "Bericht boosten",
"keyboard_shortcuts.column": "Op één van de kolommen focussen",
- "keyboard_shortcuts.compose": "Tekstveld voor toots focussen",
+ "keyboard_shortcuts.compose": "Tekstveld om een bericht te schrijven focussen",
"keyboard_shortcuts.description": "Omschrijving",
"keyboard_shortcuts.direct": "Jouw directe berichten tonen",
"keyboard_shortcuts.down": "Naar beneden in de lijst bewegen",
- "keyboard_shortcuts.enter": "Toot volledig tonen",
+ "keyboard_shortcuts.enter": "Volledig bericht tonen",
"keyboard_shortcuts.favourite": "Aan jouw favorieten toevoegen",
"keyboard_shortcuts.favourites": "Favorieten tonen",
"keyboard_shortcuts.federated": "Globale tijdlijn tonen",
@@ -247,7 +247,7 @@
"keyboard_shortcuts.my_profile": "Jouw profiel tonen",
"keyboard_shortcuts.notifications": "Meldingen tonen",
"keyboard_shortcuts.open_media": "Media openen",
- "keyboard_shortcuts.pinned": "Jouw vastgezette toots tonen",
+ "keyboard_shortcuts.pinned": "Jouw vastgemaakte berichten tonen",
"keyboard_shortcuts.profile": "Gebruikersprofiel auteur openen",
"keyboard_shortcuts.reply": "Reageren",
"keyboard_shortcuts.requests": "Jouw volgverzoeken tonen",
@@ -256,7 +256,7 @@
"keyboard_shortcuts.start": "\"Aan de slag\" tonen",
"keyboard_shortcuts.toggle_hidden": "Inhoudswaarschuwing tonen/verbergen",
"keyboard_shortcuts.toggle_sensitivity": "Media tonen/verbergen",
- "keyboard_shortcuts.toot": "Nieuwe toot schrijven",
+ "keyboard_shortcuts.toot": "Nieuw bericht schrijven",
"keyboard_shortcuts.unfocus": "Tekst- en zoekveld ontfocussen",
"keyboard_shortcuts.up": "Naar boven in de lijst bewegen",
"lightbox.close": "Sluiten",
@@ -289,12 +289,12 @@
"navigation_bar.blocks": "Geblokkeerde gebruikers",
"navigation_bar.bookmarks": "Bladwijzers",
"navigation_bar.community_timeline": "Lokale tijdlijn",
- "navigation_bar.compose": "Nieuw toot schrijven",
+ "navigation_bar.compose": "Nieuw bericht schrijven",
"navigation_bar.direct": "Directe berichten",
"navigation_bar.discover": "Ontdekken",
"navigation_bar.domain_blocks": "Geblokkeerde domeinen",
"navigation_bar.edit_profile": "Profiel bewerken",
- "navigation_bar.explore": "Explore",
+ "navigation_bar.explore": "Verkennen",
"navigation_bar.favourites": "Favorieten",
"navigation_bar.filters": "Filters",
"navigation_bar.follow_requests": "Volgverzoeken",
@@ -305,23 +305,23 @@
"navigation_bar.logout": "Uitloggen",
"navigation_bar.mutes": "Genegeerde gebruikers",
"navigation_bar.personal": "Persoonlijk",
- "navigation_bar.pins": "Vastgezette toots",
+ "navigation_bar.pins": "Vastgemaakte berichten",
"navigation_bar.preferences": "Instellingen",
"navigation_bar.public_timeline": "Globale tijdlijn",
"navigation_bar.security": "Beveiliging",
- "notification.admin.sign_up": "{name} signed up",
- "notification.favourite": "{name} voegde jouw toot als favoriet toe",
+ "notification.admin.sign_up": "{name} heeft zich aangemeld",
+ "notification.favourite": "{name} voegde jouw bericht als favoriet toe",
"notification.follow": "{name} volgt jou nu",
"notification.follow_request": "{name} wil jou graag volgen",
"notification.mention": "{name} vermeldde jou",
"notification.own_poll": "Jouw poll is beëindigd",
"notification.poll": "Een poll waaraan jij hebt meegedaan is beëindigd",
- "notification.reblog": "{name} boostte jouw toot",
- "notification.status": "{name} heeft zojuist een toot geplaatst",
- "notification.update": "{name} edited a post",
+ "notification.reblog": "{name} boostte jouw bericht",
+ "notification.status": "{name} heeft zojuist een bericht geplaatst",
+ "notification.update": "{name} heeft een bericht bewerkt",
"notifications.clear": "Meldingen verwijderen",
"notifications.clear_confirmation": "Weet je het zeker dat je al jouw meldingen wilt verwijderen?",
- "notifications.column_settings.admin.sign_up": "New sign-ups:",
+ "notifications.column_settings.admin.sign_up": "Nieuwe aanmeldingen:",
"notifications.column_settings.alert": "Desktopmeldingen",
"notifications.column_settings.favourite": "Favorieten:",
"notifications.column_settings.filter_bar.advanced": "Alle categorieën tonen",
@@ -335,10 +335,10 @@
"notifications.column_settings.reblog": "Boosts:",
"notifications.column_settings.show": "In kolom tonen",
"notifications.column_settings.sound": "Geluid afspelen",
- "notifications.column_settings.status": "Nieuwe toots:",
+ "notifications.column_settings.status": "Nieuwe berichten:",
"notifications.column_settings.unread_notifications.category": "Ongelezen meldingen",
"notifications.column_settings.unread_notifications.highlight": "Ongelezen meldingen markeren",
- "notifications.column_settings.update": "Edits:",
+ "notifications.column_settings.update": "Bewerkingen:",
"notifications.filter.all": "Alles",
"notifications.filter.boosts": "Boosts",
"notifications.filter.favourites": "Favorieten",
@@ -365,7 +365,7 @@
"poll.votes": "{votes, plural, one {# stem} other {# stemmen}}",
"poll_button.add_poll": "Poll toevoegen",
"poll_button.remove_poll": "Poll verwijderen",
- "privacy.change": "Zichtbaarheid van toot aanpassen",
+ "privacy.change": "Zichtbaarheid van bericht aanpassen",
"privacy.direct.long": "Alleen aan vermelde gebruikers tonen",
"privacy.direct.short": "Direct",
"privacy.private.long": "Alleen aan volgers tonen",
@@ -378,100 +378,100 @@
"regeneration_indicator.label": "Aan het laden…",
"regeneration_indicator.sublabel": "Jouw tijdlijn wordt aangemaakt!",
"relative_time.days": "{number}d",
- "relative_time.full.days": "{number, plural, one {# day} other {# days}} ago",
- "relative_time.full.hours": "{number, plural, one {# hour} other {# hours}} ago",
- "relative_time.full.just_now": "just now",
- "relative_time.full.minutes": "{number, plural, one {# minute} other {# minutes}} ago",
- "relative_time.full.seconds": "{number, plural, one {# second} other {# seconds}} ago",
+ "relative_time.full.days": "{number, plural, one {# dag} other {# dagen}} geleden",
+ "relative_time.full.hours": "{number, plural, one {# uur} other {# uur}} geleden",
+ "relative_time.full.just_now": "zojuist",
+ "relative_time.full.minutes": "{number, plural, one {# minuut} other {# minuten}} geleden",
+ "relative_time.full.seconds": "{number, plural, one {# seconde} other {# seconden}} geleden",
"relative_time.hours": "{number}u",
"relative_time.just_now": "nu",
"relative_time.minutes": "{number}m",
"relative_time.seconds": "{number}s",
"relative_time.today": "vandaag",
"reply_indicator.cancel": "Annuleren",
- "report.block": "Block",
- "report.block_explanation": "You will not see their posts. They will not be able to see your posts or follow you. They will be able to tell that they are blocked.",
- "report.categories.other": "Other",
+ "report.block": "Blokkeren",
+ "report.block_explanation": "Je kunt diens berichten niet zien. Je kunt door diegene niet gevolgd worden en jouw berichten zijn onzichtbaar. Diegene kan zien dat die door jou is geblokkeerd.",
+ "report.categories.other": "Overig",
"report.categories.spam": "Spam",
- "report.categories.violation": "Content violates one or more server rules",
- "report.category.subtitle": "Choose the best match",
- "report.category.title": "Tell us what's going on with this {type}",
- "report.category.title_account": "profile",
- "report.category.title_status": "post",
- "report.close": "Done",
- "report.comment.title": "Is there anything else you think we should know?",
+ "report.categories.violation": "De inhoud overtreedt een of meerdere serverregels",
+ "report.category.subtitle": "Kies wat het meeste overeenkomt",
+ "report.category.title": "Vertel ons wat er met dit {type} aan de hand is",
+ "report.category.title_account": "profiel",
+ "report.category.title_status": "bericht",
+ "report.close": "Klaar",
+ "report.comment.title": "Zijn er nog andere dingen waarvan je denkt dat wij dat moeten weten?",
"report.forward": "Naar {target} doorsturen",
"report.forward_hint": "Het account bevindt zich op een andere server. Wil je daar eveneens een geanonimiseerde kopie van deze rapportage naar toe sturen?",
- "report.mute": "Mute",
- "report.mute_explanation": "You will not see their posts. They can still follow you and see your posts and will not know that they are muted.",
- "report.next": "Next",
+ "report.mute": "Negeren",
+ "report.mute_explanation": "Je kunt diens berichten niet zien. Je kunt nog wel gevolgd worden en jouw berichten zijn nog zichtbaar, maar diegene kan niet zien dat die wordt genegeerd.",
+ "report.next": "Volgende",
"report.placeholder": "Extra opmerkingen",
- "report.reasons.dislike": "I don't like it",
- "report.reasons.dislike_description": "It is not something you want to see",
- "report.reasons.other": "It's something else",
- "report.reasons.other_description": "The issue does not fit into other categories",
- "report.reasons.spam": "It's spam",
- "report.reasons.spam_description": "Malicious links, fake engagement, or repetitive replies",
- "report.reasons.violation": "It violates server rules",
- "report.reasons.violation_description": "You are aware that it breaks specific rules",
- "report.rules.subtitle": "Select all that apply",
- "report.rules.title": "Which rules are being violated?",
- "report.statuses.subtitle": "Select all that apply",
- "report.statuses.title": "Are there any posts that back up this report?",
+ "report.reasons.dislike": "Ik vind het niet leuk",
+ "report.reasons.dislike_description": "Het is iets wat je niet wilt zien",
+ "report.reasons.other": "Het is iets anders",
+ "report.reasons.other_description": "Het probleem past niet in een andere categorie",
+ "report.reasons.spam": "Het is spam",
+ "report.reasons.spam_description": "Schadelijke links, reclame, misleiding of herhalende antwoorden",
+ "report.reasons.violation": "Het schendt de serverregels",
+ "report.reasons.violation_description": "Je weet dat het specifieke regels schendt",
+ "report.rules.subtitle": "Selecteer wat van toepassing is",
+ "report.rules.title": "Welke regels worden geschonden?",
+ "report.statuses.subtitle": "Selecteer wat van toepassing is",
+ "report.statuses.title": "Zijn er berichten die deze rapportage ondersteunen?",
"report.submit": "Verzenden",
"report.target": "{target} rapporteren",
- "report.thanks.take_action": "Here are your options for controlling what you see on Mastodon:",
- "report.thanks.take_action_actionable": "While we review this, you can take action against @{name}:",
- "report.thanks.title": "Don't want to see this?",
- "report.thanks.title_actionable": "Thanks for reporting, we'll look into this.",
- "report.unfollow": "Unfollow @{name}",
- "report.unfollow_explanation": "You are following this account. To not see their posts in your home feed anymore, unfollow them.",
+ "report.thanks.take_action": "Hier zijn jouw opties waarmee je kunt bepalen wat je in Mastodon wilt zien:",
+ "report.thanks.take_action_actionable": "Terwijl wij jouw rapportage beroordelen, kun je deze acties ondernemen tegen @{name}:",
+ "report.thanks.title": "Wil je dit niet zien?",
+ "report.thanks.title_actionable": "Dank je voor het rapporteren. Wij gaan er naar kijken.",
+ "report.unfollow": "@{name} ontvolgen",
+ "report.unfollow_explanation": "Je volgt dit account. Om diens berichten niet meer op jouw starttijdlijn te zien, kun je diegene ontvolgen.",
"search.placeholder": "Zoeken",
"search_popout.search_format": "Geavanceerd zoeken",
- "search_popout.tips.full_text": "Gebruik gewone tekst om te zoeken in jouw toots, gebooste toots, favorieten en in toots waarin je bent vermeldt, en tevens naar gebruikersnamen, weergavenamen en hashtags.",
+ "search_popout.tips.full_text": "Gebruik gewone tekst om te zoeken in jouw berichten, gebooste berichten, favorieten en in berichten waarin je bent vermeldt, en tevens naar gebruikersnamen, weergavenamen en hashtags.",
"search_popout.tips.hashtag": "hashtag",
- "search_popout.tips.status": "toot",
+ "search_popout.tips.status": "bericht",
"search_popout.tips.text": "Gebruik gewone tekst om te zoeken op weergavenamen, gebruikersnamen en hashtags",
"search_popout.tips.user": "gebruiker",
"search_results.accounts": "Gebruikers",
- "search_results.all": "All",
+ "search_results.all": "Alles",
"search_results.hashtags": "Hashtags",
- "search_results.nothing_found": "Could not find anything for these search terms",
- "search_results.statuses": "Toots",
- "search_results.statuses_fts_disabled": "Het zoeken in toots is op deze Mastodon-server niet ingeschakeld.",
+ "search_results.nothing_found": "Deze zoektermen leveren geen resultaat op",
+ "search_results.statuses": "Berichten",
+ "search_results.statuses_fts_disabled": "Het zoeken in berichten is op deze Mastodon-server niet ingeschakeld.",
"search_results.total": "{count, number} {count, plural, one {resultaat} other {resultaten}}",
"status.admin_account": "Moderatie-omgeving van @{name} openen",
- "status.admin_status": "Deze toot in de moderatie-omgeving openen",
+ "status.admin_status": "Dit bericht in de moderatie-omgeving openen",
"status.block": "@{name} blokkeren",
"status.bookmark": "Bladwijzer toevoegen",
"status.cancel_reblog_private": "Niet langer boosten",
- "status.cannot_reblog": "Deze toot kan niet geboost worden",
- "status.copy": "Link naar toot kopiëren",
+ "status.cannot_reblog": "Dit bericht kan niet geboost worden",
+ "status.copy": "Link naar bericht kopiëren",
"status.delete": "Verwijderen",
"status.detailed_status": "Uitgebreide gespreksweergave",
"status.direct": "@{name} een direct bericht sturen",
- "status.edit": "Edit",
- "status.edited": "Edited {date}",
- "status.edited_x_times": "Edited {count, plural, one {{count} time} other {{count} times}}",
+ "status.edit": "Bewerken",
+ "status.edited": "Bewerkt op {date}",
+ "status.edited_x_times": "{count, plural, one {{count} keer} other {{count} keer}} bewerkt",
"status.embed": "Insluiten",
"status.favourite": "Favoriet",
"status.filtered": "Gefilterd",
- "status.history.created": "{name} created {date}",
- "status.history.edited": "{name} edited {date}",
+ "status.history.created": "{name} plaatste dit {date}",
+ "status.history.edited": "{name} bewerkte dit {date}",
"status.load_more": "Meer laden",
"status.media_hidden": "Media verborgen",
"status.mention": "@{name} vermelden",
"status.more": "Meer",
"status.mute": "@{name} negeren",
"status.mute_conversation": "Negeer gesprek",
- "status.open": "Volledige toot tonen",
+ "status.open": "Volledig bericht tonen",
"status.pin": "Aan profielpagina vastmaken",
- "status.pinned": "Vastgemaakte toot",
+ "status.pinned": "Vastgemaakt bericht",
"status.read_more": "Meer lezen",
"status.reblog": "Boosten",
"status.reblog_private": "Boost naar oorspronkelijke ontvangers",
"status.reblogged_by": "{name} boostte",
- "status.reblogs.empty": "Niemand heeft deze toot nog geboost. Wanneer iemand dit doet, valt dat hier te zien.",
+ "status.reblogs.empty": "Niemand heeft dit bericht nog geboost. Wanneer iemand dit doet, valt dat hier te zien.",
"status.redraft": "Verwijderen en herschrijven",
"status.remove_bookmark": "Bladwijzer verwijderen",
"status.reply": "Reageren",
@@ -502,7 +502,7 @@
"timeline_hint.remote_resource_not_displayed": "{resource} van andere servers worden niet getoond.",
"timeline_hint.resources.followers": "Volgers",
"timeline_hint.resources.follows": "Volgend",
- "timeline_hint.resources.statuses": "Oudere toots",
+ "timeline_hint.resources.statuses": "Oudere berichten",
"trends.counter_by_accounts": "{count, plural, one {{counter} persoon} other {{counter} personen}} zijn aan het praten",
"trends.trending_now": "Huidige trends",
"ui.beforeunload": "Je concept gaat verloren wanneer je Mastodon verlaat.",
--
cgit
From b58db8f12eb19787ee3bd1ec8abab21027b3d4ef Mon Sep 17 00:00:00 2001
From: Eugen Rochko
Date: Fri, 25 Mar 2022 19:31:35 +0100
Subject: Add workaround for YouTube Shorts links (#17869)
* Add workaround for YouTube Shorts links
* Update link_details_extractor_spec.rb
---
app/lib/link_details_extractor.rb | 2 +-
spec/lib/link_details_extractor_spec.rb | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)
(limited to 'app')
diff --git a/app/lib/link_details_extractor.rb b/app/lib/link_details_extractor.rb
index fabbd244d..b0c4e4f42 100644
--- a/app/lib/link_details_extractor.rb
+++ b/app/lib/link_details_extractor.rb
@@ -208,7 +208,7 @@ class LinkDetailsExtractor
end
def valid_url_or_nil(str, same_origin_only: false)
- return if str.blank?
+ return if str.blank? || str == 'null'
url = @original_url + Addressable::URI.parse(str)
diff --git a/spec/lib/link_details_extractor_spec.rb b/spec/lib/link_details_extractor_spec.rb
index 84bb4579c..7ea867c61 100644
--- a/spec/lib/link_details_extractor_spec.rb
+++ b/spec/lib/link_details_extractor_spec.rb
@@ -25,6 +25,14 @@ RSpec.describe LinkDetailsExtractor do
expect(subject.canonical_url).to eq 'https://foo.com/article'
end
end
+
+ context 'when canonical URL is set to "null"' do
+ let(:html) { '' }
+
+ it 'ignores the canonical URLs' do
+ expect(subject.canonical_url).to eq original_url
+ end
+ end
end
context 'when structured data is present' do
--
cgit
From f65eaa5aae8a71431bdcfb9c49c869cbdbc4da3f Mon Sep 17 00:00:00 2001
From: Claire
Date: Fri, 25 Mar 2022 21:00:59 +0100
Subject: Add admin dashboard checks for Elasticsearch version (#17863)
---
app/lib/admin/system_check.rb | 1 +
app/lib/admin/system_check/elasticsearch_check.rb | 39 +++++++++++++++++++++++
config/locales/en.yml | 5 +++
3 files changed, 45 insertions(+)
create mode 100644 app/lib/admin/system_check/elasticsearch_check.rb
(limited to 'app')
diff --git a/app/lib/admin/system_check.rb b/app/lib/admin/system_check.rb
index afb20cb47..877a42ef6 100644
--- a/app/lib/admin/system_check.rb
+++ b/app/lib/admin/system_check.rb
@@ -5,6 +5,7 @@ class Admin::SystemCheck
Admin::SystemCheck::DatabaseSchemaCheck,
Admin::SystemCheck::SidekiqProcessCheck,
Admin::SystemCheck::RulesCheck,
+ Admin::SystemCheck::ElasticsearchCheck,
].freeze
def self.perform
diff --git a/app/lib/admin/system_check/elasticsearch_check.rb b/app/lib/admin/system_check/elasticsearch_check.rb
new file mode 100644
index 000000000..1b48a5415
--- /dev/null
+++ b/app/lib/admin/system_check/elasticsearch_check.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+class Admin::SystemCheck::ElasticsearchCheck < Admin::SystemCheck::BaseCheck
+ def pass?
+ return true unless Chewy.enabled?
+
+ running_version.present? && compatible_version?
+ end
+
+ def message
+ if running_version.present?
+ Admin::SystemCheck::Message.new(:elasticsearch_version_check, I18n.t('admin.system_checks.elasticsearch_version_check.version_comparison', running_version: running_version, required_version: required_version))
+ else
+ Admin::SystemCheck::Message.new(:elasticsearch_running_check)
+ end
+ end
+
+ private
+
+ def running_version
+ @running_version ||= begin
+ Chewy.client.info['version']['number']
+ rescue Faraday::ConnectionFailed
+ nil
+ end
+ end
+
+ def required_version
+ '7.x'
+ end
+
+ def compatible_version?
+ Gem::Version.new(running_version) >= Gem::Version.new(required_version)
+ end
+
+ def missing_queues
+ @missing_queues ||= Sidekiq::ProcessSet.new.reduce(SIDEKIQ_QUEUES) { |queues, process| queues - process['queues'] }
+ end
+end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index a6ded38f7..db29922fa 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -780,6 +780,11 @@ en:
message_html: You haven't defined any server rules.
sidekiq_process_check:
message_html: No Sidekiq process running for the %{value} queue(s). Please review your Sidekiq configuration
+ elasticsearch_running_check:
+ message_html: Could not connect to Elasticsearch. Please check that it is running, or disable full-text search
+ elasticsearch_version_check:
+ message_html: "Incompatible Elasticsearch version: %{value}"
+ version_comparison: "Elasticsearch %{running_version} is running while %{required_version} is required"
tags:
review: Review status
updated_msg: Hashtag settings updated successfully
--
cgit
From e3a220306181f9aeda41940bfb11e4350d113e77 Mon Sep 17 00:00:00 2001
From: Eugen Rochko
Date: Sat, 26 Mar 2022 00:26:50 +0100
Subject: Add offset pagination to trends in REST API (#17872)
---
app/controllers/api/v1/trends/links_controller.rb | 26 +++++++++++++++++++++-
.../api/v1/trends/statuses_controller.rb | 24 +++++++++++++++++++-
app/controllers/api/v1/trends/tags_controller.rb | 26 +++++++++++++++++++++-
app/models/trends/query.rb | 4 ++--
4 files changed, 75 insertions(+), 5 deletions(-)
(limited to 'app')
diff --git a/app/controllers/api/v1/trends/links_controller.rb b/app/controllers/api/v1/trends/links_controller.rb
index ad20e7f8b..b1cde5a4b 100644
--- a/app/controllers/api/v1/trends/links_controller.rb
+++ b/app/controllers/api/v1/trends/links_controller.rb
@@ -3,6 +3,10 @@
class Api::V1::Trends::LinksController < Api::BaseController
before_action :set_links
+ after_action :insert_pagination_headers
+
+ DEFAULT_LINKS_LIMIT = 10
+
def index
render json: @links, each_serializer: REST::Trends::LinkSerializer
end
@@ -20,6 +24,26 @@ class Api::V1::Trends::LinksController < Api::BaseController
end
def links_from_trends
- Trends.links.query.allowed.in_locale(content_locale).limit(limit_param(10))
+ Trends.links.query.allowed.in_locale(content_locale).offset(offset_param).limit(limit_param(DEFAULT_LINKS_LIMIT))
+ end
+
+ def insert_pagination_headers
+ set_pagination_headers(next_path, prev_path)
+ end
+
+ def pagination_params(core_params)
+ params.slice(:limit).permit(:limit).merge(core_params)
+ end
+
+ def next_path
+ api_v1_trends_links_url pagination_params(offset: offset_param + limit_param(DEFAULT_LINKS_LIMIT))
+ end
+
+ def prev_path
+ api_v1_trends_links_url pagination_params(offset: offset_param - limit_param(DEFAULT_LINKS_LIMIT)) if offset_param > limit_param(DEFAULT_LINKS_LIMIT)
+ end
+
+ def offset_param
+ params[:offset].to_i
end
end
diff --git a/app/controllers/api/v1/trends/statuses_controller.rb b/app/controllers/api/v1/trends/statuses_controller.rb
index d4ec97ae5..4977803fb 100644
--- a/app/controllers/api/v1/trends/statuses_controller.rb
+++ b/app/controllers/api/v1/trends/statuses_controller.rb
@@ -3,6 +3,8 @@
class Api::V1::Trends::StatusesController < Api::BaseController
before_action :set_statuses
+ after_action :insert_pagination_headers
+
def index
render json: @statuses, each_serializer: REST::StatusSerializer
end
@@ -22,6 +24,26 @@ class Api::V1::Trends::StatusesController < Api::BaseController
def statuses_from_trends
scope = Trends.statuses.query.allowed.in_locale(content_locale)
scope = scope.filtered_for(current_account) if user_signed_in?
- scope.limit(limit_param(DEFAULT_STATUSES_LIMIT))
+ scope.offset(offset_param).limit(limit_param(DEFAULT_STATUSES_LIMIT))
+ end
+
+ def insert_pagination_headers
+ set_pagination_headers(next_path, prev_path)
+ end
+
+ def pagination_params(core_params)
+ params.slice(:limit).permit(:limit).merge(core_params)
+ end
+
+ def next_path
+ api_v1_trends_statuses_url pagination_params(offset: offset_param + limit_param(DEFAULT_STATUSES_LIMIT))
+ end
+
+ def prev_path
+ api_v1_trends_statuses_url pagination_params(offset: offset_param - limit_param(DEFAULT_STATUSES_LIMIT)) if offset_param > limit_param(DEFAULT_STATUSES_LIMIT)
+ end
+
+ def offset_param
+ params[:offset].to_i
end
end
diff --git a/app/controllers/api/v1/trends/tags_controller.rb b/app/controllers/api/v1/trends/tags_controller.rb
index 1334b72d2..d77857871 100644
--- a/app/controllers/api/v1/trends/tags_controller.rb
+++ b/app/controllers/api/v1/trends/tags_controller.rb
@@ -3,6 +3,10 @@
class Api::V1::Trends::TagsController < Api::BaseController
before_action :set_tags
+ after_action :insert_pagination_headers
+
+ DEFAULT_TAGS_LIMIT = 10
+
def index
render json: @tags, each_serializer: REST::TagSerializer
end
@@ -12,10 +16,30 @@ class Api::V1::Trends::TagsController < Api::BaseController
def set_tags
@tags = begin
if Setting.trends
- Trends.tags.query.allowed.limit(limit_param(10))
+ Trends.tags.query.allowed.limit(limit_param(DEFAULT_TAGS_LIMIT))
else
[]
end
end
end
+
+ def insert_pagination_headers
+ set_pagination_headers(next_path, prev_path)
+ end
+
+ def pagination_params(core_params)
+ params.slice(:limit).permit(:limit).merge(core_params)
+ end
+
+ def next_path
+ api_v1_trends_tags_url pagination_params(offset: offset_param + limit_param(DEFAULT_TAGS_LIMIT))
+ end
+
+ def prev_path
+ api_v1_trends_tags_url pagination_params(offset: offset_param - limit_param(DEFAULT_TAGS_LIMIT)) if offset_param > limit_param(DEFAULT_TAGS_LIMIT)
+ end
+
+ def offset_param
+ params[:offset].to_i
+ end
end
diff --git a/app/models/trends/query.rb b/app/models/trends/query.rb
index 64a4c0c1f..231b65228 100644
--- a/app/models/trends/query.rb
+++ b/app/models/trends/query.rb
@@ -37,7 +37,7 @@ class Trends::Query
end
def offset!(value)
- @offset = value
+ @offset = value.to_i
self
end
@@ -46,7 +46,7 @@ class Trends::Query
end
def limit!(value)
- @limit = value
+ @limit = value.to_i
self
end
--
cgit
From 71f2b95106b2e75d3efb40040b29c216c2d99ee6 Mon Sep 17 00:00:00 2001
From: Eugen Rochko
Date: Sat, 26 Mar 2022 00:38:44 +0100
Subject: Fix edits with no actual changes being allowed (#17843)
* Fix edits with no actual changes being allowed locally
* Fix edits with no actual changes being allowed through ActivityPub
* Fix false positive changes caused by description processing in model
* Fix not recording poll expiration update
* Fix test
* Revert changes to ProcessStatusUpdateService
* Various fixes and improvements
* Fix code style issues
* Various changes and improvements
* Add guard clause
---
.../activitypub/parser/media_attachment_parser.rb | 4 ++-
app/models/concerns/status_snapshot_concern.rb | 35 ++++++++++++++++++++++
app/models/media_attachment.rb | 7 +----
app/models/status.rb | 21 +------------
.../activitypub/process_status_update_service.rb | 22 +++++++-------
app/services/update_status_service.rb | 28 ++++++++++++++---
spec/models/media_attachment_spec.rb | 8 -----
.../process_status_update_service_spec.rb | 31 +++++++++++++++++--
spec/services/update_status_service_spec.rb | 17 +++++++++++
9 files changed, 121 insertions(+), 52 deletions(-)
create mode 100644 app/models/concerns/status_snapshot_concern.rb
(limited to 'app')
diff --git a/app/lib/activitypub/parser/media_attachment_parser.rb b/app/lib/activitypub/parser/media_attachment_parser.rb
index 1798e58a4..30bea1f0e 100644
--- a/app/lib/activitypub/parser/media_attachment_parser.rb
+++ b/app/lib/activitypub/parser/media_attachment_parser.rb
@@ -27,7 +27,9 @@ class ActivityPub::Parser::MediaAttachmentParser
end
def description
- @json['summary'].presence || @json['name'].presence
+ str = @json['summary'].presence || @json['name'].presence
+ str = str.strip[0...MediaAttachment::MAX_DESCRIPTION_LENGTH] if str.present?
+ str
end
def focus
diff --git a/app/models/concerns/status_snapshot_concern.rb b/app/models/concerns/status_snapshot_concern.rb
new file mode 100644
index 000000000..9741b9aeb
--- /dev/null
+++ b/app/models/concerns/status_snapshot_concern.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+module StatusSnapshotConcern
+ extend ActiveSupport::Concern
+
+ included do
+ has_many :edits, class_name: 'StatusEdit', inverse_of: :status, dependent: :destroy
+ end
+
+ def edited?
+ edited_at.present?
+ end
+
+ def build_snapshot(account_id: nil, at_time: nil, rate_limit: true)
+ # We don't use `edits#new` here to avoid it having saved when the
+ # status is saved, since we want to control that manually
+
+ StatusEdit.new(
+ status_id: id,
+ text: text,
+ spoiler_text: spoiler_text,
+ sensitive: sensitive,
+ ordered_media_attachment_ids: ordered_media_attachment_ids&.dup || media_attachments.pluck(:id),
+ media_descriptions: ordered_media_attachments.map(&:description),
+ poll_options: preloadable_poll&.options&.dup,
+ account_id: account_id || self.account_id,
+ created_at: at_time || edited_at,
+ rate_limit: rate_limit
+ )
+ end
+
+ def snapshot!(**options)
+ build_snapshot(**options).save!
+ end
+end
diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb
index a3115637e..21c663e47 100644
--- a/app/models/media_attachment.rb
+++ b/app/models/media_attachment.rb
@@ -185,7 +185,7 @@ class MediaAttachment < ApplicationRecord
remotable_attachment :thumbnail, IMAGE_LIMIT, suppress_errors: true, download_on_assign: false
validates :account, presence: true
- validates :description, length: { maximum: MAX_DESCRIPTION_LENGTH }, if: :local?
+ validates :description, length: { maximum: MAX_DESCRIPTION_LENGTH }
validates :file, presence: true, if: :local?
validates :thumbnail, absence: true, if: -> { local? && !audio_or_video? }
@@ -258,7 +258,6 @@ class MediaAttachment < ApplicationRecord
after_commit :enqueue_processing, on: :create
after_commit :reset_parent_cache, on: :update
- before_create :prepare_description, unless: :local?
before_create :set_unknown_type
before_create :set_processing
@@ -306,10 +305,6 @@ class MediaAttachment < ApplicationRecord
self.type = :unknown if file.blank? && !type_changed?
end
- def prepare_description
- self.description = description.strip[0...MAX_DESCRIPTION_LENGTH] unless description.nil?
- end
-
def set_type_and_extension
self.type = begin
if VIDEO_MIME_TYPES.include?(file_content_type)
diff --git a/app/models/status.rb b/app/models/status.rb
index 5b984543e..bf5a49b7f 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -35,6 +35,7 @@ class Status < ApplicationRecord
include Paginable
include Cacheable
include StatusThreadingConcern
+ include StatusSnapshotConcern
include RateLimitable
rate_limit by: :account, family: :statuses
@@ -59,8 +60,6 @@ class Status < ApplicationRecord
belongs_to :thread, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :replies, optional: true
belongs_to :reblog, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblogs, optional: true
- has_many :edits, class_name: 'StatusEdit', inverse_of: :status, dependent: :destroy
-
has_many :favourites, inverse_of: :status, dependent: :destroy
has_many :bookmarks, inverse_of: :status, dependent: :destroy
has_many :reblogs, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblog, dependent: :destroy
@@ -212,24 +211,6 @@ class Status < ApplicationRecord
public_visibility? || unlisted_visibility?
end
- def snapshot!(account_id: nil, at_time: nil, rate_limit: true)
- edits.create!(
- text: text,
- spoiler_text: spoiler_text,
- sensitive: sensitive,
- ordered_media_attachment_ids: ordered_media_attachment_ids || media_attachments.pluck(:id),
- media_descriptions: ordered_media_attachments.map(&:description),
- poll_options: preloadable_poll&.options,
- account_id: account_id || self.account_id,
- created_at: at_time || edited_at,
- rate_limit: rate_limit
- )
- end
-
- def edited?
- edited_at.present?
- end
-
alias sign? distributable?
def with_media?
diff --git a/app/services/activitypub/process_status_update_service.rb b/app/services/activitypub/process_status_update_service.rb
index 47a788c30..6dc14d8c2 100644
--- a/app/services/activitypub/process_status_update_service.rb
+++ b/app/services/activitypub/process_status_update_service.rb
@@ -4,6 +4,8 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
include JsonLdHelper
def call(status, json)
+ raise ArgumentError, 'Status has unsaved changes' if status.changed?
+
@json = json
@status_parser = ActivityPub::Parser::StatusParser.new(@json)
@uri = @status_parser.uri
@@ -17,16 +19,19 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
last_edit_date = status.edited_at.presence || status.created_at
+ # Since we rely on tracking of previous changes, ensure clean slate
+ status.clear_changes_information
+
# Only allow processing one create/update per status at a time
RedisLock.acquire(lock_options) do |lock|
if lock.acquired?
Status.transaction do
- create_previous_edit!
+ record_previous_edit!
update_media_attachments!
update_poll!
update_immediate_attributes!
update_metadata!
- create_edit!
+ create_edits!
end
queue_poll_notifications!
@@ -216,19 +221,14 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
{ redis: Redis.current, key: "create:#{@uri}", autorelease: 15.minutes.seconds }
end
- def create_previous_edit!
- # We only need to create a previous edit when no previous edits exist, e.g.
- # when the status has never been edited. For other cases, we always create
- # an edit, so the step can be skipped
-
- return if @status.edits.any?
-
- @status.snapshot!(at_time: @status.created_at, rate_limit: false)
+ def record_previous_edit!
+ @previous_edit = @status.build_snapshot(at_time: @status.created_at, rate_limit: false) if @status.edits.empty?
end
- def create_edit!
+ def create_edits!
return unless significant_changes?
+ @previous_edit&.save!
@status.snapshot!(account_id: @account.id, rate_limit: false)
end
diff --git a/app/services/update_status_service.rb b/app/services/update_status_service.rb
index 055e5968d..c4c934976 100644
--- a/app/services/update_status_service.rb
+++ b/app/services/update_status_service.rb
@@ -4,6 +4,8 @@ class UpdateStatusService < BaseService
include Redisable
include LanguagesHelper
+ class NoChangesSubmittedError < StandardError; end
+
# @param [Status] status
# @param [Integer] account_id
# @param [Hash] options
@@ -17,6 +19,8 @@ class UpdateStatusService < BaseService
@status = status
@options = options
@account_id = account_id
+ @media_attachments_changed = false
+ @poll_changed = false
Status.transaction do
create_previous_edit!
@@ -32,18 +36,24 @@ class UpdateStatusService < BaseService
broadcast_updates!
@status
+ rescue NoChangesSubmittedError
+ # For calls that result in no changes, swallow the error
+ # but get back to the original state
+
+ @status.reload
end
private
def update_media_attachments!
- previous_media_attachments = @status.media_attachments.to_a
+ previous_media_attachments = @status.ordered_media_attachments.to_a
next_media_attachments = validate_media!
added_media_attachments = next_media_attachments - previous_media_attachments
MediaAttachment.where(id: added_media_attachments.map(&:id)).update_all(status_id: @status.id)
@status.ordered_media_attachment_ids = (@options[:media_ids] || []).map(&:to_i) & next_media_attachments.map(&:id)
+ @media_attachments_changed = previous_media_attachments.map(&:id) != @status.ordered_media_attachment_ids
@status.media_attachments.reload
end
@@ -69,20 +79,23 @@ class UpdateStatusService < BaseService
# If for some reasons the options were changed, it invalidates all previous
# votes, so we need to remove them
- poll_changed = true if @options[:poll][:options] != poll.options || ActiveModel::Type::Boolean.new.cast(@options[:poll][:multiple]) != poll.multiple
+ @poll_changed = true if @options[:poll][:options] != poll.options || ActiveModel::Type::Boolean.new.cast(@options[:poll][:multiple]) != poll.multiple
poll.options = @options[:poll][:options]
poll.hide_totals = @options[:poll][:hide_totals] || false
poll.multiple = @options[:poll][:multiple] || false
poll.expires_in = @options[:poll][:expires_in]
- poll.reset_votes! if poll_changed
+ poll.reset_votes! if @poll_changed
poll.save!
@status.poll_id = poll.id
elsif previous_poll.present?
previous_poll.destroy
+ @poll_changed = true
@status.poll_id = nil
end
+
+ @poll_changed = true if @previous_expires_at != @status.preloadable_poll&.expires_at
end
def update_immediate_attributes!
@@ -90,8 +103,11 @@ class UpdateStatusService < BaseService
@status.spoiler_text = @options[:spoiler_text] || '' if @options.key?(:spoiler_text)
@status.sensitive = @options[:sensitive] || @options[:spoiler_text].present? if @options.key?(:sensitive) || @options.key?(:spoiler_text)
@status.language = valid_locale_cascade(@options[:language], @status.language, @status.account.user&.preferred_posting_language, I18n.default_locale)
- @status.edited_at = Time.now.utc
+ # We raise here to rollback the entire transaction
+ raise NoChangesSubmittedError unless significant_changes?
+
+ @status.edited_at = Time.now.utc
@status.save!
end
@@ -137,4 +153,8 @@ class UpdateStatusService < BaseService
def create_edit!
@status.snapshot!(account_id: @account_id)
end
+
+ def significant_changes?
+ @status.changed? || @poll_changed || @media_attachments_changed
+ end
end
diff --git a/spec/models/media_attachment_spec.rb b/spec/models/media_attachment_spec.rb
index 7360b23cf..cbd9a09c5 100644
--- a/spec/models/media_attachment_spec.rb
+++ b/spec/models/media_attachment_spec.rb
@@ -186,14 +186,6 @@ RSpec.describe MediaAttachment, type: :model do
expect(media.valid?).to be false
end
- describe 'descriptions for remote attachments' do
- it 'are cut off at 1500 characters' do
- media = Fabricate(:media_attachment, description: 'foo' * 1000, remote_url: 'http://example.com/blah.jpg')
-
- expect(media.description.size).to be <= 1_500
- end
- end
-
describe 'size limit validation' do
it 'rejects video files that are too large' do
stub_const 'MediaAttachment::IMAGE_LIMIT', 100.megabytes
diff --git a/spec/services/activitypub/process_status_update_service_spec.rb b/spec/services/activitypub/process_status_update_service_spec.rb
index 788c7c9d9..f87adcae1 100644
--- a/spec/services/activitypub/process_status_update_service_spec.rb
+++ b/spec/services/activitypub/process_status_update_service_spec.rb
@@ -46,6 +46,29 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
expect(status.reload.spoiler_text).to eq 'Show more'
end
+ context 'with no changes at all' do
+ let(:payload) do
+ {
+ '@context': 'https://www.w3.org/ns/activitystreams',
+ id: 'foo',
+ type: 'Note',
+ content: 'Hello world',
+ }
+ end
+
+ before do
+ subject.call(status, json)
+ end
+
+ it 'does not create any edits' do
+ expect(status.reload.edits).to be_empty
+ end
+
+ it 'does not mark status as edited' do
+ expect(status.edited?).to be false
+ end
+ end
+
context 'with no changes and originally with no ordered_media_attachment_ids' do
let(:payload) do
{
@@ -61,8 +84,12 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
subject.call(status, json)
end
- it 'does not record an update' do
- expect(status.reload.edited?).to be false
+ it 'does not create any edits' do
+ expect(status.reload.edits).to be_empty
+ end
+
+ it 'does not mark status as edited' do
+ expect(status.edited?).to be false
end
end
diff --git a/spec/services/update_status_service_spec.rb b/spec/services/update_status_service_spec.rb
index 78cc89cd4..71a73be5b 100644
--- a/spec/services/update_status_service_spec.rb
+++ b/spec/services/update_status_service_spec.rb
@@ -3,6 +3,23 @@ require 'rails_helper'
RSpec.describe UpdateStatusService, type: :service do
subject { described_class.new }
+ context 'when nothing changes' do
+ let!(:status) { Fabricate(:status, text: 'Foo', language: 'en') }
+
+ before do
+ allow(ActivityPub::DistributionWorker).to receive(:perform_async)
+ subject.call(status, status.account_id, text: 'Foo')
+ end
+
+ it 'does not create an edit' do
+ expect(status.reload.edits).to be_empty
+ end
+
+ it 'does not notify anyone' do
+ expect(ActivityPub::DistributionWorker).to_not have_received(:perform_async)
+ end
+ end
+
context 'when text changes' do
let!(:status) { Fabricate(:status, text: 'Foo') }
let(:preview_card) { Fabricate(:preview_card) }
--
cgit
From 6907605026a5d46acf8a5f3aaf5384807c1d8d3c Mon Sep 17 00:00:00 2001
From: Jeong Arm
Date: Sat, 26 Mar 2022 08:39:54 +0900
Subject: Add stop delivery link also for failing instance (#17871)
---
app/views/admin/instances/show.html.haml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'app')
diff --git a/app/views/admin/instances/show.html.haml b/app/views/admin/instances/show.html.haml
index 70912a4f5..ef4de602d 100644
--- a/app/views/admin/instances/show.html.haml
+++ b/app/views/admin/instances/show.html.haml
@@ -87,7 +87,8 @@
- else
%span.negative-hint
= t('admin.instances.availability.failures_recorded', count: @instance.delivery_failure_tracker.days)
- = link_to t('admin.instances.delivery.clear'), clear_delivery_errors_admin_instance_path(@instance), data: { confirm: t('admin.accounts.are_you_sure'), method: :post } unless @instance.exhausted_deliveries_days.empty?
+ %span= link_to t('admin.instances.delivery.clear'), clear_delivery_errors_admin_instance_path(@instance), data: { confirm: t('admin.accounts.are_you_sure'), method: :post } unless @instance.exhausted_deliveries_days.empty?
+ %span= link_to t('admin.instances.delivery.stop'), stop_delivery_admin_instance_path(@instance), data: { confirm: t('admin.accounts.are_you_sure'), method: :post }
- if @instance.purgeable?
%p= t('admin.instances.purge_description_html')
--
cgit
From 52813830bee5607332b49bee2916956286ec5dc1 Mon Sep 17 00:00:00 2001
From: mayaeh
Date: Sat, 26 Mar 2022 10:52:51 +0900
Subject: Add a hashtag public link to the trending hashtag page (#17140)
* Add a hashtag public link to the hashtag management page
* Add support for element 'target' to Counter.js.
Remove 'rel' element.
* Update app/javascript/mastodon/components/admin/Counter.js
Co-authored-by: Claire
Co-authored-by: Eugen Rochko
Co-authored-by: Claire
---
app/javascript/mastodon/components/admin/Counter.js | 5 +++--
app/views/admin/tags/show.html.haml | 2 +-
2 files changed, 4 insertions(+), 3 deletions(-)
(limited to 'app')
diff --git a/app/javascript/mastodon/components/admin/Counter.js b/app/javascript/mastodon/components/admin/Counter.js
index 6edb7bcfc..5a5b2b869 100644
--- a/app/javascript/mastodon/components/admin/Counter.js
+++ b/app/javascript/mastodon/components/admin/Counter.js
@@ -33,6 +33,7 @@ export default class Counter extends React.PureComponent {
label: PropTypes.string.isRequired,
href: PropTypes.string,
params: PropTypes.object,
+ target: PropTypes.string,
};
state = {
@@ -54,7 +55,7 @@ export default class Counter extends React.PureComponent {
}
render () {
- const { label, href } = this.props;
+ const { label, href, target } = this.props;
const { loading, data } = this.state;
let content;
@@ -100,7 +101,7 @@ export default class Counter extends React.PureComponent {
if (href) {
return (
-
+
{inner}
);
diff --git a/app/views/admin/tags/show.html.haml b/app/views/admin/tags/show.html.haml
index 007dc005e..df72bd5f5 100644
--- a/app/views/admin/tags/show.html.haml
+++ b/app/views/admin/tags/show.html.haml
@@ -11,7 +11,7 @@
.dashboard
.dashboard__item
- = react_admin_component :counter, measure: 'tag_accounts', start_at: @time_period.first, end_at: @time_period.last, params: { id: @tag.id }, label: t('admin.trends.tags.dashboard.tag_accounts_measure')
+ = react_admin_component :counter, measure: 'tag_accounts', start_at: @time_period.first, end_at: @time_period.last, params: { id: @tag.id }, label: t('admin.trends.tags.dashboard.tag_accounts_measure'), href: tag_url(@tag), target: '_blank'
.dashboard__item
= react_admin_component :counter, measure: 'tag_uses', start_at: @time_period.first, end_at: @time_period.last, params: { id: @tag.id }, label: t('admin.trends.tags.dashboard.tag_uses_measure')
.dashboard__item
--
cgit
From 2dd30804b62f750c2780b7043318cbe00d137429 Mon Sep 17 00:00:00 2001
From: Eugen Rochko
Date: Sat, 26 Mar 2022 02:53:13 +0100
Subject: Change how unconfirmed accounts are displayed in admin UI (#17874)
Fix #17815
---
app/models/account.rb | 2 +-
app/models/user.rb | 6 +++++-
app/views/admin/accounts/_account.html.haml | 2 +-
3 files changed, 7 insertions(+), 3 deletions(-)
(limited to 'app')
diff --git a/app/models/account.rb b/app/models/account.rb
index 1717f1605..a8c5df208 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -128,13 +128,13 @@ class Account < ApplicationRecord
:approved?,
:pending?,
:disabled?,
+ :unconfirmed?,
:unconfirmed_or_pending?,
:role,
:admin?,
:moderator?,
:staff?,
:locale,
- :hides_network?,
:shows_application?,
to: :user,
prefix: true,
diff --git a/app/models/user.rb b/app/models/user.rb
index 146bdcd2a..f2d9c49eb 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -208,8 +208,12 @@ class User < ApplicationRecord
confirmed? && approved? && !disabled? && !account.suspended? && !account.memorial? && account.moved_to_account_id.nil?
end
+ def unconfirmed?
+ !confirmed?
+ end
+
def unconfirmed_or_pending?
- !(confirmed? && approved?)
+ unconfirmed? || pending?
end
def inactive_message
diff --git a/app/views/admin/accounts/_account.html.haml b/app/views/admin/accounts/_account.html.haml
index 2df91301e..82dd8dfb2 100644
--- a/app/views/admin/accounts/_account.html.haml
+++ b/app/views/admin/accounts/_account.html.haml
@@ -1,4 +1,4 @@
-.batch-table__row{ class: [!account.suspended? && account.user_pending? && 'batch-table__row--attention', account.suspended? && 'batch-table__row--muted'] }
+.batch-table__row{ class: [!account.suspended? && account.user_pending? && 'batch-table__row--attention', (account.suspended? || account.user_unconfirmed?) && 'batch-table__row--muted'] }
%label.batch-table__row__select.batch-table__row__select--aligned.batch-checkbox
= f.check_box :account_ids, { multiple: true, include_hidden: false }, account.id
.batch-table__row__content.batch-table__row__content--unpadded
--
cgit
From cefa526c6d3a45df2d0fcb7643ced828e2e87dea Mon Sep 17 00:00:00 2001
From: Eugen Rochko
Date: Sat, 26 Mar 2022 02:53:34 +0100
Subject: Refactor formatter (#17828)
* Refactor formatter
* Move custom emoji pre-rendering logic to view helpers
* Move more methods out of Formatter
* Fix code style issues
* Remove Formatter
* Add inline poll options to RSS feeds
* Remove unused helper method
* Fix code style issues
* Various fixes and improvements
* Fix test
---
app/chewy/statuses_index.rb | 2 +-
app/controllers/api/web/embeds_controller.rb | 2 +-
app/helpers/accounts_helper.rb | 6 +-
app/helpers/admin/trends/statuses_helper.rb | 5 +-
app/helpers/application_helper.rb | 4 +
app/helpers/formatting_helper.rb | 19 +
app/helpers/routing_helper.rb | 3 +-
app/helpers/statuses_helper.rb | 14 -
app/lib/activitypub/activity/create.rb | 4 +-
app/lib/emoji_formatter.rb | 98 ++++
app/lib/extractor.rb | 82 +++-
app/lib/feed_manager.rb | 3 +-
app/lib/formatter.rb | 294 -----------
app/lib/html_aware_formatter.rb | 38 ++
app/lib/plain_text_formatter.rb | 30 ++
app/lib/rss/serializer.rb | 23 +-
app/lib/text_formatter.rb | 158 ++++++
app/mailers/application_mailer.rb | 1 +
app/serializers/activitypub/actor_serializer.rb | 7 +-
app/serializers/activitypub/note_serializer.rb | 6 +-
app/serializers/rest/account_serializer.rb | 7 +-
app/serializers/rest/announcement_serializer.rb | 4 +-
app/serializers/rest/status_edit_serializer.rb | 4 +-
app/serializers/rest/status_serializer.rb | 4 +-
app/services/fetch_link_card_service.rb | 2 +-
app/views/accounts/_bio.html.haml | 6 +-
app/views/admin/accounts/show.html.haml | 6 +-
app/views/admin/reports/_status.html.haml | 6 +-
app/views/admin/reports/show.html.haml | 2 +-
app/views/directories/index.html.haml | 2 +-
app/views/disputes/strikes/show.html.haml | 2 +-
app/views/notification_mailer/_status.html.haml | 4 +-
app/views/notification_mailer/_status.text.erb | 2 +-
app/views/notification_mailer/digest.text.erb | 2 +-
app/views/statuses/_detailed_status.html.haml | 5 +-
app/views/statuses/_poll.html.haml | 4 +-
app/views/statuses/_simple_status.html.haml | 5 +-
app/views/user_mailer/warning.html.haml | 2 +-
config/initializers/twitter_regex.rb | 26 -
spec/lib/emoji_formatter_spec.rb | 55 +++
spec/lib/formatter_spec.rb | 626 ------------------------
spec/lib/html_aware_formatter.rb | 44 ++
spec/lib/plain_text_formatter_spec.rb | 24 +
spec/lib/text_formatter_spec.rb | 313 ++++++++++++
44 files changed, 932 insertions(+), 1024 deletions(-)
create mode 100644 app/helpers/formatting_helper.rb
create mode 100644 app/lib/emoji_formatter.rb
delete mode 100644 app/lib/formatter.rb
create mode 100644 app/lib/html_aware_formatter.rb
create mode 100644 app/lib/plain_text_formatter.rb
create mode 100644 app/lib/text_formatter.rb
create mode 100644 spec/lib/emoji_formatter_spec.rb
delete mode 100644 spec/lib/formatter_spec.rb
create mode 100644 spec/lib/html_aware_formatter.rb
create mode 100644 spec/lib/plain_text_formatter_spec.rb
create mode 100644 spec/lib/text_formatter_spec.rb
(limited to 'app')
diff --git a/app/chewy/statuses_index.rb b/app/chewy/statuses_index.rb
index 65cbb6fcd..d119f7cac 100644
--- a/app/chewy/statuses_index.rb
+++ b/app/chewy/statuses_index.rb
@@ -57,7 +57,7 @@ class StatusesIndex < Chewy::Index
field :id, type: 'long'
field :account_id, type: 'long'
- field :text, type: 'text', value: ->(status) { [status.spoiler_text, Formatter.instance.plaintext(status)].concat(status.ordered_media_attachments.map(&:description)).concat(status.preloadable_poll ? status.preloadable_poll.options : []).join("\n\n") } do
+ field :text, type: 'text', value: ->(status) { [status.spoiler_text, PlainTextFormatter.new(status.text, status.local?).to_s].concat(status.ordered_media_attachments.map(&:description)).concat(status.preloadable_poll ? status.preloadable_poll.options : []).join("\n\n") } do
field :stemmed, type: 'text', analyzer: 'content'
end
diff --git a/app/controllers/api/web/embeds_controller.rb b/app/controllers/api/web/embeds_controller.rb
index 741ba910f..58f6345e6 100644
--- a/app/controllers/api/web/embeds_controller.rb
+++ b/app/controllers/api/web/embeds_controller.rb
@@ -15,7 +15,7 @@ class Api::Web::EmbedsController < Api::Web::BaseController
return not_found if oembed.nil?
begin
- oembed[:html] = Formatter.instance.sanitize(oembed[:html], Sanitize::Config::MASTODON_OEMBED)
+ oembed[:html] = Sanitize.fragment(oembed[:html], Sanitize::Config::MASTODON_OEMBED)
rescue ArgumentError
return not_found
end
diff --git a/app/helpers/accounts_helper.rb b/app/helpers/accounts_helper.rb
index a33961724..557f60f26 100644
--- a/app/helpers/accounts_helper.rb
+++ b/app/helpers/accounts_helper.rb
@@ -2,10 +2,12 @@
module AccountsHelper
def display_name(account, **options)
+ str = account.display_name.presence || account.username
+
if options[:custom_emojify]
- Formatter.instance.format_display_name(account, **options)
+ prerender_custom_emojis(h(str), account.emojis)
else
- account.display_name.presence || account.username
+ str
end
end
diff --git a/app/helpers/admin/trends/statuses_helper.rb b/app/helpers/admin/trends/statuses_helper.rb
index d16e3dd12..214c1e2a6 100644
--- a/app/helpers/admin/trends/statuses_helper.rb
+++ b/app/helpers/admin/trends/statuses_helper.rb
@@ -12,9 +12,6 @@ module Admin::Trends::StatusesHelper
return '' if text.blank?
- html = Formatter.instance.send(:encode, text)
- html = Formatter.instance.send(:encode_custom_emojis, html, status.emojis, prefers_autoplay?)
-
- html.html_safe # rubocop:disable Rails/OutputSafety
+ prerender_custom_emojis(h(text), status.emojis)
end
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index e997570b5..651a98a85 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -239,4 +239,8 @@ module ApplicationHelper
end
end.values
end
+
+ def prerender_custom_emojis(html, custom_emojis)
+ EmojiFormatter.new(html, custom_emojis, animate: prefers_autoplay?).to_s
+ end
end
diff --git a/app/helpers/formatting_helper.rb b/app/helpers/formatting_helper.rb
new file mode 100644
index 000000000..66e9e1e91
--- /dev/null
+++ b/app/helpers/formatting_helper.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+module FormattingHelper
+ def html_aware_format(text, local, options = {})
+ HtmlAwareFormatter.new(text, local, options).to_s
+ end
+
+ def linkify(text, options = {})
+ TextFormatter.new(text, options).to_s
+ end
+
+ def extract_plain_text(text, local)
+ PlainTextFormatter.new(text, local).to_s
+ end
+
+ def status_content_format(status)
+ html_aware_format(status.text, status.local?, preloaded_accounts: [status.account] + (status.respond_to?(:active_mentions) ? status.active_mentions.map(&:account) : []))
+ end
+end
diff --git a/app/helpers/routing_helper.rb b/app/helpers/routing_helper.rb
index fb24a1b28..f95f46a56 100644
--- a/app/helpers/routing_helper.rb
+++ b/app/helpers/routing_helper.rb
@@ -2,6 +2,7 @@
module RoutingHelper
extend ActiveSupport::Concern
+
include Rails.application.routes.url_helpers
include ActionView::Helpers::AssetTagHelper
include Webpacker::Helper
@@ -22,8 +23,6 @@ module RoutingHelper
full_asset_url(asset_pack_path(source, **options))
end
- private
-
def use_storage?
Rails.configuration.x.use_s3 || Rails.configuration.x.use_swift
end
diff --git a/app/helpers/statuses_helper.rb b/app/helpers/statuses_helper.rb
index d328f89b7..e92b4c839 100644
--- a/app/helpers/statuses_helper.rb
+++ b/app/helpers/statuses_helper.rb
@@ -113,20 +113,6 @@ module StatusesHelper
end
end
- private
-
- def simplified_text(text)
- text.dup.tap do |new_text|
- URI.extract(new_text).each do |url|
- new_text.gsub!(url, '')
- end
-
- new_text.gsub!(Account::MENTION_RE, '')
- new_text.gsub!(Tag::HASHTAG_RE, '')
- new_text.gsub!(/\s+/, '')
- end
- end
-
def embedded_view?
params[:controller] == EMBEDDED_CONTROLLER && params[:action] == EMBEDDED_ACTION
end
diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb
index ea8d146d4..f4f98e29c 100644
--- a/app/lib/activitypub/activity/create.rb
+++ b/app/lib/activitypub/activity/create.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
class ActivityPub::Activity::Create < ActivityPub::Activity
+ include FormattingHelper
+
def perform
dereference_object!
@@ -367,7 +369,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
end
def converted_text
- Formatter.instance.linkify([@status_parser.title.presence, @status_parser.spoiler_text.presence, @status_parser.url || @status_parser.uri].compact.join("\n\n"))
+ linkify([@status_parser.title.presence, @status_parser.spoiler_text.presence, @status_parser.url || @status_parser.uri].compact.join("\n\n"))
end
def unsupported_media_type?(mime_type)
diff --git a/app/lib/emoji_formatter.rb b/app/lib/emoji_formatter.rb
new file mode 100644
index 000000000..f808f3a22
--- /dev/null
+++ b/app/lib/emoji_formatter.rb
@@ -0,0 +1,98 @@
+# frozen_string_literal: true
+
+class EmojiFormatter
+ include RoutingHelper
+
+ DISALLOWED_BOUNDING_REGEX = /[[:alnum:]:]/.freeze
+
+ attr_reader :html, :custom_emojis, :options
+
+ # @param [ActiveSupport::SafeBuffer] html
+ # @param [Array] custom_emojis
+ # @param [Hash] options
+ # @option options [Boolean] :animate
+ def initialize(html, custom_emojis, options = {})
+ raise ArgumentError unless html.html_safe?
+
+ @html = html
+ @custom_emojis = custom_emojis
+ @options = options
+ end
+
+ def to_s
+ return html if custom_emojis.empty? || html.blank?
+
+ i = -1
+ tag_open_index = nil
+ inside_shortname = false
+ shortname_start_index = -1
+ invisible_depth = 0
+ last_index = 0
+ result = ''.dup
+
+ while i + 1 < html.size
+ i += 1
+
+ if invisible_depth.zero? && inside_shortname && html[i] == ':'
+ inside_shortname = false
+ shortcode = html[shortname_start_index + 1..i - 1]
+ char_after = html[i + 1]
+
+ next unless (char_after.nil? || !DISALLOWED_BOUNDING_REGEX.match?(char_after)) && (emoji = emoji_map[shortcode])
+
+ result << html[last_index..shortname_start_index - 1] if shortname_start_index.positive?
+ result << image_for_emoji(shortcode, emoji)
+ last_index = i + 1
+ elsif tag_open_index && html[i] == '>'
+ tag = html[tag_open_index..i]
+ tag_open_index = nil
+
+ if invisible_depth.positive?
+ invisible_depth += count_tag_nesting(tag)
+ elsif tag == ''
+ invisible_depth = 1
+ end
+ elsif html[i] == '<'
+ tag_open_index = i
+ inside_shortname = false
+ elsif !tag_open_index && html[i] == ':' && (i.zero? || !DISALLOWED_BOUNDING_REGEX.match?(html[i - 1]))
+ inside_shortname = true
+ shortname_start_index = i
+ end
+ end
+
+ result << html[last_index..-1]
+
+ result.html_safe # rubocop:disable Rails/OutputSafety
+ end
+
+ private
+
+ def emoji_map
+ @emoji_map ||= custom_emojis.each_with_object({}) { |e, h| h[e.shortcode] = [full_asset_url(e.image.url), full_asset_url(e.image.url(:static))] }
+ end
+
+ def count_tag_nesting(tag)
+ if tag[1] == '/'
+ -1
+ elsif tag[-2] == '/'
+ 0
+ else
+ 1
+ end
+ end
+
+ def image_for_emoji(shortcode, emoji)
+ original_url, static_url = emoji
+
+ if animate?
+ image_tag(original_url, draggable: false, class: 'emojione', alt: ":#{shortcode}:", title: ":#{shortcode}:")
+ else
+ image_tag(original_url, draggable: false, class: 'emojione custom-emoji', alt: ":#{shortcode}:", title: ":#{shortcode}:", data: { original: original_url, static: static_url })
+ end
+ end
+
+ def animate?
+ @options[:animate]
+ end
+end
diff --git a/app/lib/extractor.rb b/app/lib/extractor.rb
index 8020aa916..ef9407864 100644
--- a/app/lib/extractor.rb
+++ b/app/lib/extractor.rb
@@ -5,18 +5,34 @@ module Extractor
module_function
- # :yields: username, list_slug, start, end
+ def extract_entities_with_indices(text, options = {}, &block)
+ entities = begin
+ extract_urls_with_indices(text, options) +
+ extract_hashtags_with_indices(text, check_url_overlap: false) +
+ extract_mentions_or_lists_with_indices(text) +
+ extract_extra_uris_with_indices(text)
+ end
+
+ return [] if entities.empty?
+
+ entities = remove_overlapping_entities(entities)
+ entities.each(&block) if block_given?
+ entities
+ end
+
def extract_mentions_or_lists_with_indices(text)
- return [] unless Twitter::TwitterText::Regex[:at_signs].match?(text)
+ return [] unless text && Twitter::TwitterText::Regex[:at_signs].match?(text)
possible_entries = []
- text.to_s.scan(Account::MENTION_RE) do |screen_name, _|
+ text.scan(Account::MENTION_RE) do |screen_name, _|
match_data = $LAST_MATCH_INFO
- after = $'
+ after = $'
+
unless Twitter::TwitterText::Regex[:end_mention_match].match?(after)
start_position = match_data.char_begin(1) - 1
- end_position = match_data.char_end(1)
+ end_position = match_data.char_end(1)
+
possible_entries << {
screen_name: screen_name,
indices: [start_position, end_position],
@@ -29,36 +45,70 @@ module Extractor
yield mention[:screen_name], mention[:indices].first, mention[:indices].last
end
end
+
possible_entries
end
- def extract_hashtags_with_indices(text, **)
- return [] unless /#/.match?(text)
+ def extract_hashtags_with_indices(text, _options = {})
+ return [] unless text&.index('#')
+
+ possible_entries = []
- tags = []
text.scan(Tag::HASHTAG_RE) do |hash_text, _|
- match_data = $LAST_MATCH_INFO
+ match_data = $LAST_MATCH_INFO
start_position = match_data.char_begin(1) - 1
- end_position = match_data.char_end(1)
- after = $'
+ end_position = match_data.char_end(1)
+ after = $'
+
if %r{\A://}.match?(after)
hash_text.match(/(.+)(https?\Z)/) do |matched|
- hash_text = matched[1]
+ hash_text = matched[1]
end_position -= matched[2].codepoint_length
end
end
- tags << {
+ possible_entries << {
hashtag: hash_text,
indices: [start_position, end_position],
}
end
- tags.each { |tag| yield tag[:hashtag], tag[:indices].first, tag[:indices].last } if block_given?
- tags
+ if block_given?
+ possible_entries.each do |tag|
+ yield tag[:hashtag], tag[:indices].first, tag[:indices].last
+ end
+ end
+
+ possible_entries
end
def extract_cashtags_with_indices(_text)
- [] # always returns empty array
+ []
+ end
+
+ def extract_extra_uris_with_indices(text)
+ return [] unless text&.index(':')
+
+ possible_entries = []
+
+ text.scan(Twitter::TwitterText::Regex[:valid_extended_uri]) do
+ valid_uri_match_data = $LAST_MATCH_INFO
+
+ start_position = valid_uri_match_data.char_begin(3)
+ end_position = valid_uri_match_data.char_end(3)
+
+ possible_entries << {
+ url: valid_uri_match_data[3],
+ indices: [start_position, end_position],
+ }
+ end
+
+ if block_given?
+ possible_entries.each do |url|
+ yield url[:url], url[:indices].first, url[:indices].last
+ end
+ end
+
+ possible_entries
end
end
diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb
index 46a55c7a4..53d1390d4 100644
--- a/app/lib/feed_manager.rb
+++ b/app/lib/feed_manager.rb
@@ -5,6 +5,7 @@ require 'singleton'
class FeedManager
include Singleton
include Redisable
+ include FormattingHelper
# Maximum number of items stored in a single feed
MAX_ITEMS = 400
@@ -445,7 +446,7 @@ class FeedManager
status = status.reblog if status.reblog?
combined_text = [
- Formatter.instance.plaintext(status),
+ extract_plain_text(status.text, status.local?),
status.spoiler_text,
status.preloadable_poll ? status.preloadable_poll.options.join("\n\n") : nil,
status.ordered_media_attachments.map(&:description).join("\n\n"),
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb
deleted file mode 100644
index b6a13163d..000000000
--- a/app/lib/formatter.rb
+++ /dev/null
@@ -1,294 +0,0 @@
-# frozen_string_literal: true
-
-require 'singleton'
-
-class Formatter
- include Singleton
- include RoutingHelper
-
- include ActionView::Helpers::TextHelper
-
- def format(status, **options)
- if status.respond_to?(:reblog?) && status.reblog?
- prepend_reblog = status.reblog.account.acct
- status = status.proper
- else
- prepend_reblog = false
- end
-
- raw_content = status.text
-
- if options[:inline_poll_options] && status.preloadable_poll
- raw_content = raw_content + "\n\n" + status.preloadable_poll.options.map { |title| "[ ] #{title}" }.join("\n")
- end
-
- return '' if raw_content.blank?
-
- unless status.local?
- html = reformat(raw_content)
- html = encode_custom_emojis(html, status.emojis, options[:autoplay]) if options[:custom_emojify]
- return html.html_safe # rubocop:disable Rails/OutputSafety
- end
-
- linkable_accounts = status.respond_to?(:active_mentions) ? status.active_mentions.map(&:account) : []
- linkable_accounts << status.account
-
- html = raw_content
- html = "RT @#{prepend_reblog} #{html}" if prepend_reblog
- html = encode_and_link_urls(html, linkable_accounts)
- html = encode_custom_emojis(html, status.emojis, options[:autoplay]) if options[:custom_emojify]
- html = simple_format(html, {}, sanitize: false)
- html = html.delete("\n")
-
- html.html_safe # rubocop:disable Rails/OutputSafety
- end
-
- def reformat(html)
- sanitize(html, Sanitize::Config::MASTODON_STRICT)
- rescue ArgumentError
- ''
- end
-
- def plaintext(status)
- return status.text if status.local?
-
- text = status.text.gsub(/( | |<\/p>)+/) { |match| "#{match}\n" }
- strip_tags(text)
- end
-
- def simplified_format(account, **options)
- return '' if account.note.blank?
-
- html = account.local? ? linkify(account.note) : reformat(account.note)
- html = encode_custom_emojis(html, account.emojis, options[:autoplay]) if options[:custom_emojify]
- html.html_safe # rubocop:disable Rails/OutputSafety
- end
-
- def sanitize(html, config)
- Sanitize.fragment(html, config)
- end
-
- def format_spoiler(status, **options)
- html = encode(status.spoiler_text)
- html = encode_custom_emojis(html, status.emojis, options[:autoplay])
- html.html_safe # rubocop:disable Rails/OutputSafety
- end
-
- def format_poll_option(status, option, **options)
- html = encode(option.title)
- html = encode_custom_emojis(html, status.emojis, options[:autoplay])
- html.html_safe # rubocop:disable Rails/OutputSafety
- end
-
- def format_display_name(account, **options)
- html = encode(account.display_name.presence || account.username)
- html = encode_custom_emojis(html, account.emojis, options[:autoplay]) if options[:custom_emojify]
- html.html_safe # rubocop:disable Rails/OutputSafety
- end
-
- def format_field(account, str, **options)
- html = account.local? ? encode_and_link_urls(str, me: true, with_domain: true) : reformat(str)
- html = encode_custom_emojis(html, account.emojis, options[:autoplay]) if options[:custom_emojify]
- html.html_safe # rubocop:disable Rails/OutputSafety
- end
-
- def linkify(text)
- html = encode_and_link_urls(text)
- html = simple_format(html, {}, sanitize: false)
- html = html.delete("\n")
-
- html.html_safe # rubocop:disable Rails/OutputSafety
- end
-
- private
-
- def html_entities
- @html_entities ||= HTMLEntities.new
- end
-
- def encode(html)
- html_entities.encode(html)
- end
-
- def encode_and_link_urls(html, accounts = nil, options = {})
- entities = utf8_friendly_extractor(html, extract_url_without_protocol: false)
-
- if accounts.is_a?(Hash)
- options = accounts
- accounts = nil
- end
-
- rewrite(html.dup, entities) do |entity|
- if entity[:url]
- link_to_url(entity, options)
- elsif entity[:hashtag]
- link_to_hashtag(entity)
- elsif entity[:screen_name]
- link_to_mention(entity, accounts, options)
- end
- end
- end
-
- def count_tag_nesting(tag)
- if tag[1] == '/' then -1
- elsif tag[-2] == '/' then 0
- else 1
- end
- end
-
- # rubocop:disable Metrics/BlockNesting
- def encode_custom_emojis(html, emojis, animate = false)
- return html if emojis.empty?
-
- emoji_map = emojis.each_with_object({}) { |e, h| h[e.shortcode] = [full_asset_url(e.image.url), full_asset_url(e.image.url(:static))] }
-
- i = -1
- tag_open_index = nil
- inside_shortname = false
- shortname_start_index = -1
- invisible_depth = 0
-
- while i + 1 < html.size
- i += 1
-
- if invisible_depth.zero? && inside_shortname && html[i] == ':'
- shortcode = html[shortname_start_index + 1..i - 1]
- emoji = emoji_map[shortcode]
-
- if emoji
- original_url, static_url = emoji
- replacement = begin
- if animate
- image_tag(original_url, draggable: false, class: 'emojione', alt: ":#{shortcode}:", title: ":#{shortcode}:")
- else
- image_tag(original_url, draggable: false, class: 'emojione custom-emoji', alt: ":#{shortcode}:", title: ":#{shortcode}:", data: { original: original_url, static: static_url })
- end
- end
- before_html = shortname_start_index.positive? ? html[0..shortname_start_index - 1] : ''
- html = before_html + replacement + html[i + 1..-1]
- i += replacement.size - (shortcode.size + 2) - 1
- else
- i -= 1
- end
-
- inside_shortname = false
- elsif tag_open_index && html[i] == '>'
- tag = html[tag_open_index..i]
- tag_open_index = nil
- if invisible_depth.positive?
- invisible_depth += count_tag_nesting(tag)
- elsif tag == ''
- invisible_depth = 1
- end
- elsif html[i] == '<'
- tag_open_index = i
- inside_shortname = false
- elsif !tag_open_index && html[i] == ':'
- inside_shortname = true
- shortname_start_index = i
- end
- end
-
- html
- end
- # rubocop:enable Metrics/BlockNesting
-
- def rewrite(text, entities)
- text = text.to_s
-
- # Sort by start index
- entities = entities.sort_by do |entity|
- indices = entity.respond_to?(:indices) ? entity.indices : entity[:indices]
- indices.first
- end
-
- result = []
-
- last_index = entities.reduce(0) do |index, entity|
- indices = entity.respond_to?(:indices) ? entity.indices : entity[:indices]
- result << encode(text[index...indices.first])
- result << yield(entity)
- indices.last
- end
-
- result << encode(text[last_index..-1])
-
- result.flatten.join
- end
-
- def utf8_friendly_extractor(text, options = {})
- # Note: I couldn't obtain list_slug with @user/list-name format
- # for mention so this requires additional check
- special = Extractor.extract_urls_with_indices(text, options)
- standard = Extractor.extract_entities_with_indices(text, options)
- extra = Extractor.extract_extra_uris_with_indices(text, options)
-
- Extractor.remove_overlapping_entities(special + standard + extra)
- end
-
- def link_to_url(entity, options = {})
- url = Addressable::URI.parse(entity[:url])
- html_attrs = { target: '_blank', rel: 'nofollow noopener noreferrer' }
-
- html_attrs[:rel] = "me #{html_attrs[:rel]}" if options[:me]
-
- Twitter::TwitterText::Autolink.send(:link_to_text, entity, link_html(entity[:url]), url, html_attrs)
- rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
- encode(entity[:url])
- end
-
- def link_to_mention(entity, linkable_accounts, options = {})
- acct = entity[:screen_name]
-
- return link_to_account(acct, options) unless linkable_accounts
-
- same_username_hits = 0
- account = nil
- username, domain = acct.split('@')
- domain = nil if TagManager.instance.local_domain?(domain)
-
- linkable_accounts.each do |item|
- same_username = item.username.casecmp(username).zero?
- same_domain = item.domain.nil? ? domain.nil? : item.domain.casecmp(domain)&.zero?
-
- if same_username && !same_domain
- same_username_hits += 1
- elsif same_username && same_domain
- account = item
- end
- end
-
- account ? mention_html(account, with_domain: same_username_hits.positive? || options[:with_domain]) : "@#{encode(acct)}"
- end
-
- def link_to_account(acct, options = {})
- username, domain = acct.split('@')
-
- domain = nil if TagManager.instance.local_domain?(domain)
- account = EntityCache.instance.mention(username, domain)
-
- account ? mention_html(account, with_domain: options[:with_domain]) : "@#{encode(acct)}"
- end
-
- def link_to_hashtag(entity)
- hashtag_html(entity[:hashtag])
- end
-
- def link_html(url)
- url = Addressable::URI.parse(url).to_s
- prefix = url.match(/\A(https?:\/\/(www\.)?|xmpp:)/).to_s
- text = url[prefix.length, 30]
- suffix = url[prefix.length + 30..-1]
- cutoff = url[prefix.length..-1].length > 30
-
- "#{encode(prefix)}#{encode(text)}#{encode(suffix)}"
- end
-
- def hashtag_html(tag)
- "##{encode(tag)}"
- end
-
- def mention_html(account, with_domain: false)
- "@#{encode(with_domain ? account.pretty_acct : account.username)}"
- end
-end
diff --git a/app/lib/html_aware_formatter.rb b/app/lib/html_aware_formatter.rb
new file mode 100644
index 000000000..64edba09b
--- /dev/null
+++ b/app/lib/html_aware_formatter.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+class HtmlAwareFormatter
+ attr_reader :text, :local, :options
+
+ alias local? local
+
+ # @param [String] text
+ # @param [Boolean] local
+ # @param [Hash] options
+ def initialize(text, local, options = {})
+ @text = text
+ @local = local
+ @options = options
+ end
+
+ def to_s
+ return ''.html_safe if text.blank?
+
+ if local?
+ linkify
+ else
+ reformat.html_safe # rubocop:disable Rails/OutputSafety
+ end
+ rescue ArgumentError
+ ''.html_safe
+ end
+
+ private
+
+ def reformat
+ Sanitize.fragment(text, Sanitize::Config::MASTODON_STRICT)
+ end
+
+ def linkify
+ TextFormatter.new(text, options).to_s
+ end
+end
diff --git a/app/lib/plain_text_formatter.rb b/app/lib/plain_text_formatter.rb
new file mode 100644
index 000000000..08aa29696
--- /dev/null
+++ b/app/lib/plain_text_formatter.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class PlainTextFormatter
+ include ActionView::Helpers::TextHelper
+
+ NEWLINE_TAGS_RE = /( | |<\/p>)+/.freeze
+
+ attr_reader :text, :local
+
+ alias local? local
+
+ def initialize(text, local)
+ @text = text
+ @local = local
+ end
+
+ def to_s
+ if local?
+ text
+ else
+ strip_tags(insert_newlines).chomp
+ end
+ end
+
+ private
+
+ def insert_newlines
+ text.gsub(NEWLINE_TAGS_RE) { |match| "#{match}\n" }
+ end
+end
diff --git a/app/lib/rss/serializer.rb b/app/lib/rss/serializer.rb
index 7e3ed1f17..d44e94221 100644
--- a/app/lib/rss/serializer.rb
+++ b/app/lib/rss/serializer.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
class RSS::Serializer
+ include FormattingHelper
+
private
def render_statuses(builder, statuses)
@@ -9,7 +11,7 @@ class RSS::Serializer
item.title(status_title(status))
.link(ActivityPub::TagManager.instance.url_for(status))
.pub_date(status.created_at)
- .description(status.spoiler_text.presence || Formatter.instance.format(status, inline_poll_options: true).to_str)
+ .description(status_description(status))
status.ordered_media_attachments.each do |media|
item.enclosure(full_asset_url(media.file.url(:original, false)), media.file.content_type, media.file.size)
@@ -19,9 +21,8 @@ class RSS::Serializer
end
def status_title(status)
- return "#{status.account.acct} deleted status" if status.destroyed?
-
preview = status.proper.spoiler_text.presence || status.proper.text
+
if preview.length > 30 || preview[0, 30].include?("\n")
preview = preview[0, 30]
preview = preview[0, preview.index("\n").presence || 30] + '…'
@@ -35,4 +36,20 @@ class RSS::Serializer
"#{status.account.acct}: #{preview}"
end
end
+
+ def status_description(status)
+ if status.proper.spoiler_text?
+ status.proper.spoiler_text
+ else
+ html = status_content_format(status.proper).to_str
+ after_html = ''
+
+ if status.proper.preloadable_poll
+ poll_options_html = status.proper.preloadable_poll.options.map { |o| "[ ] #{o}" }.join(' ')
+ after_html = "
#{poll_options_html}
"
+ end
+
+ "#{html}#{after_html}"
+ end
+ end
end
diff --git a/app/lib/text_formatter.rb b/app/lib/text_formatter.rb
new file mode 100644
index 000000000..48e2fc233
--- /dev/null
+++ b/app/lib/text_formatter.rb
@@ -0,0 +1,158 @@
+# frozen_string_literal: true
+
+class TextFormatter
+ include ActionView::Helpers::TextHelper
+ include ERB::Util
+ include RoutingHelper
+
+ URL_PREFIX_REGEX = /\A(https?:\/\/(www\.)?|xmpp:)/.freeze
+
+ DEFAULT_REL = %w(nofollow noopener noreferrer).freeze
+
+ DEFAULT_OPTIONS = {
+ multiline: true,
+ }.freeze
+
+ attr_reader :text, :options
+
+ # @param [String] text
+ # @param [Hash] options
+ # @option options [Boolean] :multiline
+ # @option options [Boolean] :with_domains
+ # @option options [Boolean] :with_rel_me
+ # @option options [Array] :preloaded_accounts
+ def initialize(text, options = {})
+ @text = text
+ @options = DEFAULT_OPTIONS.merge(options)
+ end
+
+ def entities
+ @entities ||= Extractor.extract_entities_with_indices(text, extract_url_without_protocol: false)
+ end
+
+ def to_s
+ return ''.html_safe if text.blank?
+
+ html = rewrite do |entity|
+ if entity[:url]
+ link_to_url(entity)
+ elsif entity[:hashtag]
+ link_to_hashtag(entity)
+ elsif entity[:screen_name]
+ link_to_mention(entity)
+ end
+ end
+
+ html = simple_format(html, {}, sanitize: false).delete("\n") if multiline?
+
+ html.html_safe # rubocop:disable Rails/OutputSafety
+ end
+
+ private
+
+ def rewrite
+ entities.sort_by! do |entity|
+ entity[:indices].first
+ end
+
+ result = ''.dup
+
+ last_index = entities.reduce(0) do |index, entity|
+ indices = entity[:indices]
+ result << h(text[index...indices.first])
+ result << yield(entity)
+ indices.last
+ end
+
+ result << h(text[last_index..-1])
+
+ result
+ end
+
+ def link_to_url(entity)
+ url = Addressable::URI.parse(entity[:url]).to_s
+ rel = with_rel_me? ? (DEFAULT_REL + %w(me)) : DEFAULT_REL
+
+ prefix = url.match(URL_PREFIX_REGEX).to_s
+ display_url = url[prefix.length, 30]
+ suffix = url[prefix.length + 30..-1]
+ cutoff = url[prefix.length..-1].length > 30
+
+ <<~HTML.squish
+ #{h(prefix)}#{h(display_url)}#{h(suffix)}
+ HTML
+ rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
+ h(entity[:url])
+ end
+
+ def link_to_hashtag(entity)
+ hashtag = entity[:hashtag]
+ url = tag_url(hashtag)
+
+ <<~HTML.squish
+ ##{h(hashtag)}
+ HTML
+ end
+
+ def link_to_mention(entity)
+ username, domain = entity[:screen_name].split('@')
+ domain = nil if local_domain?(domain)
+ account = nil
+
+ if preloaded_accounts?
+ same_username_hits = 0
+
+ preloaded_accounts.each do |other_account|
+ same_username = other_account.username.casecmp(username).zero?
+ same_domain = other_account.domain.nil? ? domain.nil? : other_account.domain.casecmp(domain)&.zero?
+
+ if same_username && !same_domain
+ same_username_hits += 1
+ elsif same_username && same_domain
+ account = other_account
+ end
+ end
+ else
+ account = entity_cache.mention(username, domain)
+ end
+
+ return "@#{h(entity[:screen_name])}" if account.nil?
+
+ url = ActivityPub::TagManager.instance.url_for(account)
+ display_username = same_username_hits&.positive? || with_domains? ? account.pretty_acct : account.username
+
+ <<~HTML.squish
+ @#{h(display_username)}
+ HTML
+ end
+
+ def entity_cache
+ @entity_cache ||= EntityCache.instance
+ end
+
+ def tag_manager
+ @tag_manager ||= TagManager.instance
+ end
+
+ delegate :local_domain?, to: :tag_manager
+
+ def multiline?
+ options[:multiline]
+ end
+
+ def with_domains?
+ options[:with_domains]
+ end
+
+ def with_rel_me?
+ options[:with_rel_me]
+ end
+
+ def preloaded_accounts
+ options[:preloaded_accounts]
+ end
+
+ def preloaded_accounts?
+ preloaded_accounts.present?
+ end
+end
diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb
index cc585c3b7..a37682eca 100644
--- a/app/mailers/application_mailer.rb
+++ b/app/mailers/application_mailer.rb
@@ -5,6 +5,7 @@ class ApplicationMailer < ActionMailer::Base
helper :application
helper :instance
+ helper :formatting
protected
diff --git a/app/serializers/activitypub/actor_serializer.rb b/app/serializers/activitypub/actor_serializer.rb
index 48707aa16..bd1648348 100644
--- a/app/serializers/activitypub/actor_serializer.rb
+++ b/app/serializers/activitypub/actor_serializer.rb
@@ -2,6 +2,7 @@
class ActivityPub::ActorSerializer < ActivityPub::Serializer
include RoutingHelper
+ include FormattingHelper
context :security
@@ -102,7 +103,7 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
end
def summary
- object.suspended? ? '' : Formatter.instance.simplified_format(object)
+ object.suspended? ? '' : html_aware_format(object.note, object.local?)
end
def icon
@@ -185,6 +186,8 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
end
class Account::FieldSerializer < ActivityPub::Serializer
+ include FormattingHelper
+
attributes :type, :name, :value
def type
@@ -192,7 +195,7 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
end
def value
- Formatter.instance.format_field(object.account, object.value)
+ html_aware_format(object.value, object.account.value?, with_rel_me: true, with_domains: true, multiline: false)
end
end
diff --git a/app/serializers/activitypub/note_serializer.rb b/app/serializers/activitypub/note_serializer.rb
index 7be2e2647..27e058199 100644
--- a/app/serializers/activitypub/note_serializer.rb
+++ b/app/serializers/activitypub/note_serializer.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
class ActivityPub::NoteSerializer < ActivityPub::Serializer
+ include FormattingHelper
+
context_extensions :atom_uri, :conversation, :sensitive, :voters_count
attributes :id, :type, :summary,
@@ -39,11 +41,11 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
end
def content
- Formatter.instance.format(object)
+ status_content_format(object)
end
def content_map
- { object.language => Formatter.instance.format(object) }
+ { object.language => content }
end
def replies
diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb
index a78ec4507..2f67e06b2 100644
--- a/app/serializers/rest/account_serializer.rb
+++ b/app/serializers/rest/account_serializer.rb
@@ -2,6 +2,7 @@
class REST::AccountSerializer < ActiveModel::Serializer
include RoutingHelper
+ include FormattingHelper
attributes :id, :username, :acct, :display_name, :locked, :bot, :discoverable, :group, :created_at,
:note, :url, :avatar, :avatar_static, :header, :header_static,
@@ -14,10 +15,12 @@ class REST::AccountSerializer < ActiveModel::Serializer
attribute :suspended, if: :suspended?
class FieldSerializer < ActiveModel::Serializer
+ include FormattingHelper
+
attributes :name, :value, :verified_at
def value
- Formatter.instance.format_field(object.account, object.value)
+ html_aware_format(object.value, object.account.local?, with_rel_me: true, with_domains: true, multiline: false)
end
end
@@ -32,7 +35,7 @@ class REST::AccountSerializer < ActiveModel::Serializer
end
def note
- object.suspended? ? '' : Formatter.instance.simplified_format(object)
+ object.suspended? ? '' : html_aware_format(object.note, object.local?)
end
def url
diff --git a/app/serializers/rest/announcement_serializer.rb b/app/serializers/rest/announcement_serializer.rb
index 9343b97d2..23b2fa514 100644
--- a/app/serializers/rest/announcement_serializer.rb
+++ b/app/serializers/rest/announcement_serializer.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
class REST::AnnouncementSerializer < ActiveModel::Serializer
+ include FormattingHelper
+
attributes :id, :content, :starts_at, :ends_at, :all_day,
:published_at, :updated_at
@@ -25,7 +27,7 @@ class REST::AnnouncementSerializer < ActiveModel::Serializer
end
def content
- Formatter.instance.linkify(object.text)
+ linkify(object.text)
end
def reactions
diff --git a/app/serializers/rest/status_edit_serializer.rb b/app/serializers/rest/status_edit_serializer.rb
index 05ccd5e94..f7a48797d 100644
--- a/app/serializers/rest/status_edit_serializer.rb
+++ b/app/serializers/rest/status_edit_serializer.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
class REST::StatusEditSerializer < ActiveModel::Serializer
+ include FormattingHelper
+
has_one :account, serializer: REST::AccountSerializer
attributes :content, :spoiler_text, :sensitive, :created_at
@@ -11,7 +13,7 @@ class REST::StatusEditSerializer < ActiveModel::Serializer
attribute :poll, if: -> { object.poll_options.present? }
def content
- Formatter.instance.format(object)
+ status_content_format(object)
end
def poll
diff --git a/app/serializers/rest/status_serializer.rb b/app/serializers/rest/status_serializer.rb
index 7c3dd673e..32c4e405e 100644
--- a/app/serializers/rest/status_serializer.rb
+++ b/app/serializers/rest/status_serializer.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
class REST::StatusSerializer < ActiveModel::Serializer
+ include FormattingHelper
+
attributes :id, :created_at, :in_reply_to_id, :in_reply_to_account_id,
:sensitive, :spoiler_text, :visibility, :language,
:uri, :url, :replies_count, :reblogs_count,
@@ -71,7 +73,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
end
def content
- Formatter.instance.format(object)
+ status_content_format(object)
end
def url
diff --git a/app/services/fetch_link_card_service.rb b/app/services/fetch_link_card_service.rb
index 239ab9b93..9c8b5ea20 100644
--- a/app/services/fetch_link_card_service.rb
+++ b/app/services/fetch_link_card_service.rb
@@ -134,7 +134,7 @@ class FetchLinkCardService < BaseService
when 'video'
@card.width = embed[:width].presence || 0
@card.height = embed[:height].presence || 0
- @card.html = Formatter.instance.sanitize(embed[:html], Sanitize::Config::MASTODON_OEMBED)
+ @card.html = Sanitize.fragment(embed[:html], Sanitize::Config::MASTODON_OEMBED)
@card.image_remote_url = (url + embed[:thumbnail_url]).to_s if embed[:thumbnail_url].present?
when 'rich'
# Most providers rely on } }
-
- it 'does not include the HTML in the URL' do
- is_expected.to include '"http://example.com/blahblahblahblah/a"'
- end
-
- it 'escapes the HTML' do
- is_expected.to include '<script>alert("Hello")</script>'
- end
- end
-
- context 'given text containing HTML code (script tag)' do
- let(:text) { '' }
-
- it 'escapes the HTML' do
- is_expected.to include '
<script>alert("Hello")</script>
'
- end
- end
-
- context 'given text containing HTML (XSS attack)' do
- let(:text) { %q{} }
-
- it 'escapes the HTML' do
- is_expected.to include '
<img src="javascript:alert('XSS');">
'
- end
- end
-
- context 'given an invalid URL' do
- let(:text) { 'http://www\.google\.com' }
-
- it 'outputs the raw URL' do
- is_expected.to eq '
http://www\.google\.com
'
- end
- end
-
- context 'given text containing a hashtag' do
- let(:text) { '#hashtag' }
-
- it 'creates a hashtag link' do
- is_expected.to include '/tags/hashtag" class="mention hashtag" rel="tag">#hashtag'
- end
- end
-
- context 'given text containing a hashtag with Unicode chars' do
- let(:text) { '#hashtagタグ' }
-
- it 'creates a hashtag link' do
- is_expected.to include '/tags/hashtag%E3%82%BF%E3%82%B0" class="mention hashtag" rel="tag">#hashtagタグ'
- end
- end
-
- context 'given a stand-alone xmpp: URI' do
- let(:text) { 'xmpp:user@instance.com' }
-
- it 'matches the full URI' do
- is_expected.to include 'href="xmpp:user@instance.com"'
- end
- end
-
- context 'given a an xmpp: URI with a query-string' do
- let(:text) { 'please join xmpp:muc@instance.com?join right now' }
-
- it 'matches the full URI' do
- is_expected.to include 'href="xmpp:muc@instance.com?join"'
- end
- end
-
- context 'given text containing a magnet: URI' do
- let(:text) { 'wikipedia gives this example of a magnet uri: magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a' }
-
- it 'matches the full URI' do
- is_expected.to include 'href="magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a"'
- end
- end
- end
-
- describe '#format_spoiler' do
- subject { Formatter.instance.format_spoiler(status) }
-
- context 'given a post containing plain text' do
- let(:status) { Fabricate(:status, text: 'text', spoiler_text: 'Secret!', uri: nil) }
-
- it 'Returns the spoiler text' do
- is_expected.to eq 'Secret!'
- end
- end
-
- context 'given a post with an emoji shortcode at the start' do
- let!(:emoji) { Fabricate(:custom_emoji) }
- let(:status) { Fabricate(:status, text: 'text', spoiler_text: ':coolcat: Secret!', uri: nil) }
- let(:text) { ':coolcat: Beep boop' }
-
- it 'converts the shortcode to an image tag' do
- is_expected.to match(/@alice Hello world'
- end
- end
-
- context 'given a post containing plain text' do
- let(:status) { Fabricate(:status, text: 'text', uri: nil) }
-
- it 'paragraphizes the text' do
- is_expected.to eq '
text
'
- end
- end
-
- context 'given a post containing line feeds' do
- let(:status) { Fabricate(:status, text: "line\nfeed", uri: nil) }
-
- it 'removes line feeds' do
- is_expected.not_to include "\n"
- end
- end
-
- context 'given a post containing linkable mentions' do
- let(:status) { Fabricate(:status, mentions: [ Fabricate(:mention, account: local_account) ], text: '@alice') }
-
- it 'creates a mention link' do
- is_expected.to include '@alice'
- end
- end
-
- context 'given a post containing unlinkable mentions' do
- let(:status) { Fabricate(:status, text: '@alice', uri: nil) }
-
- it 'does not create a mention link' do
- is_expected.to include '@alice'
- end
- end
-
- context do
- subject do
- status = Fabricate(:status, text: text, uri: nil)
- Formatter.instance.format(status)
- end
-
- include_examples 'encode and link URLs'
- end
-
- context 'given a post with custom_emojify option' do
- let!(:emoji) { Fabricate(:custom_emoji) }
- let(:status) { Fabricate(:status, account: local_account, text: text) }
-
- subject { Formatter.instance.format(status, custom_emojify: true) }
-
- context 'given a post with an emoji shortcode at the start' do
- let(:text) { ':coolcat: Beep boop' }
-
- it 'converts the shortcode to an image tag' do
- is_expected.to match(/
:coolcat: Beep boop ' }
-
- it 'converts the shortcode to an image tag' do
- is_expected.to match(/
Beep :coolcat: boop
' }
-
- it 'converts the shortcode to an image tag' do
- is_expected.to match(/Beep :coolcat::coolcat:
' }
-
- it 'does not touch the shortcodes' do
- is_expected.to match(/
:coolcat::coolcat:<\/p>/)
- end
- end
-
- context 'given a post with an emoji shortcode at the end' do
- let(:text) { '
Beep boop :coolcat:
' }
-
- it 'converts the shortcode to an image tag' do
- is_expected.to match(/ alert("Hello")' }
-
- it 'strips the scripts' do
- is_expected.to_not include ''
- end
- end
-
- context 'given a post containing malicious classes' do
- let(:text) { 'Show more' }
-
- it 'strips the malicious classes' do
- is_expected.to_not include 'status__content__spoiler-link'
- end
- end
- end
-
- describe '#plaintext' do
- subject { Formatter.instance.plaintext(status) }
-
- context 'given a post with local status' do
- let(:status) { Fabricate(:status, text: '
a text by a nerd who uses an HTML tag in text
', uri: nil) }
-
- it 'returns the raw text' do
- is_expected.to eq '
a text by a nerd who uses an HTML tag in text
'
- end
- end
-
- context 'given a post with remote status' do
- let(:status) { Fabricate(:status, account: remote_account, text: '') }
-
- it 'returns tag-stripped text' do
- is_expected.to eq ''
- end
- end
- end
-
- describe '#simplified_format' do
- subject { Formatter.instance.simplified_format(account) }
-
- context 'given a post with local status' do
- let(:account) { Fabricate(:account, domain: nil, note: text) }
-
- context 'given a post containing linkable mentions for local accounts' do
- let(:text) { '@alice' }
-
- before { local_account }
-
- it 'creates a mention link' do
- is_expected.to eq '
'
- end
- end
-
- context 'given a post containing linkable mentions for remote accounts' do
- let(:text) { '@bob@remote.test' }
-
- before { remote_account }
-
- it 'creates a mention link' do
- is_expected.to eq '
'
- end
- end
-
- context 'given a post containing unlinkable mentions' do
- let(:text) { '@alice' }
-
- it 'does not create a mention link' do
- is_expected.to eq '
@alice
'
- end
- end
-
- context 'given a post with custom_emojify option' do
- let!(:emoji) { Fabricate(:custom_emoji) }
-
- before { account.note = text }
- subject { Formatter.instance.simplified_format(account, custom_emojify: true) }
-
- context 'given a post with an emoji shortcode at the start' do
- let(:text) { ':coolcat: Beep boop' }
-
- it 'converts the shortcode to an image tag' do
- is_expected.to match(/
alert("Hello")' }
- let(:account) { Fabricate(:account, domain: 'remote', note: text) }
-
- it 'reformats' do
- is_expected.to_not include ''
- end
-
- context 'with custom_emojify option' do
- let!(:emoji) { Fabricate(:custom_emoji, domain: remote_account.domain) }
-
- before { remote_account.note = text }
-
- subject { Formatter.instance.simplified_format(remote_account, custom_emojify: true) }
-
- context 'given a post with an emoji shortcode at the start' do
- let(:text) { '
:coolcat: Beep boop ' }
-
- it 'converts shortcode to image tag' do
- is_expected.to match(/
Beep :coolcat: boop
' }
-
- it 'converts shortcode to image tag' do
- is_expected.to match(/Beep :coolcat::coolcat:' }
-
- it 'does not touch the shortcodes' do
- is_expected.to match(/
:coolcat::coolcat:<\/p>/)
- end
- end
-
- context 'given a post with an emoji shortcode at the end' do
- let(:text) { '
Beep boop :coolcat:
' }
-
- it 'converts shortcode to image tag' do
- is_expected.to match(/ alert("Hello")' }
-
- subject { Formatter.instance.sanitize(html, Sanitize::Config::MASTODON_STRICT) }
-
- it 'sanitizes' do
- is_expected.to eq ''
- end
- end
-end
diff --git a/spec/lib/html_aware_formatter.rb b/spec/lib/html_aware_formatter.rb
new file mode 100644
index 000000000..18d23abf5
--- /dev/null
+++ b/spec/lib/html_aware_formatter.rb
@@ -0,0 +1,44 @@
+require 'rails_helper'
+
+RSpec.describe HtmlAwareFormatter do
+ describe '#to_s' do
+ subject { described_class.new(text, local).to_s }
+
+ context 'when local' do
+ let(:local) { true }
+ let(:text) { 'Foo bar' }
+
+ it 'returns formatted text' do
+ is_expected.to eq '
Foo bar
'
+ end
+ end
+
+ context 'when remote' do
+ let(:local) { false }
+
+ context 'given plain text' do
+ let(:text) { 'Beep boop' }
+
+ it 'keeps the plain text' do
+ is_expected.to include 'Beep boop'
+ end
+ end
+
+ context 'given text containing script tags' do
+ let(:text) { '' }
+
+ it 'strips the scripts' do
+ is_expected.to_not include ''
+ end
+ end
+
+ context 'given text containing malicious classes' do
+ let(:text) { 'Show more' }
+
+ it 'strips the malicious classes' do
+ is_expected.to_not include 'status__content__spoiler-link'
+ end
+ end
+ end
+ end
+end
diff --git a/spec/lib/plain_text_formatter_spec.rb b/spec/lib/plain_text_formatter_spec.rb
new file mode 100644
index 000000000..c3d0ee630
--- /dev/null
+++ b/spec/lib/plain_text_formatter_spec.rb
@@ -0,0 +1,24 @@
+require 'rails_helper'
+
+RSpec.describe PlainTextFormatter do
+ describe '#to_s' do
+ subject { described_class.new(status.text, status.local?).to_s }
+
+ context 'given a post with local status' do
+ let(:status) { Fabricate(:status, text: '
a text by a nerd who uses an HTML tag in text
', uri: nil) }
+
+ it 'returns the raw text' do
+ is_expected.to eq '
a text by a nerd who uses an HTML tag in text
'
+ end
+ end
+
+ context 'given a post with remote status' do
+ let(:remote_account) { Fabricate(:account, domain: 'remote.test', username: 'bob', url: 'https://remote.test/') }
+ let(:status) { Fabricate(:status, account: remote_account, text: '
Hello
') }
+
+ it 'returns tag-stripped text' do
+ is_expected.to eq 'Hello'
+ end
+ end
+ end
+end
diff --git a/spec/lib/text_formatter_spec.rb b/spec/lib/text_formatter_spec.rb
new file mode 100644
index 000000000..52a9d2498
--- /dev/null
+++ b/spec/lib/text_formatter_spec.rb
@@ -0,0 +1,313 @@
+require 'rails_helper'
+
+RSpec.describe TextFormatter do
+ describe '#to_s' do
+ let(:preloaded_accounts) { nil }
+
+ subject { described_class.new(text, preloaded_accounts: preloaded_accounts).to_s }
+
+ context 'given text containing plain text' do
+ let(:text) { 'text' }
+
+ it 'paragraphizes the text' do
+ is_expected.to eq '
text
'
+ end
+ end
+
+ context 'given text containing line feeds' do
+ let(:text) { "line\nfeed" }
+
+ it 'removes line feeds' do
+ is_expected.not_to include "\n"
+ end
+ end
+
+ context 'given text containing linkable mentions' do
+ let(:preloaded_accounts) { [Fabricate(:account, username: 'alice')] }
+ let(:text) { '@alice' }
+
+ it 'creates a mention link' do
+ is_expected.to include '@alice'
+ end
+ end
+
+ context 'given text containing unlinkable mentions' do
+ let(:preloaded_accounts) { [] }
+ let(:text) { '@alice' }
+
+ it 'does not create a mention link' do
+ is_expected.to include '@alice'
+ end
+ end
+
+ context 'given a stand-alone medium URL' do
+ let(:text) { 'https://hackernoon.com/the-power-to-build-communities-a-response-to-mark-zuckerberg-3f2cac9148a4' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="https://hackernoon.com/the-power-to-build-communities-a-response-to-mark-zuckerberg-3f2cac9148a4"'
+ end
+ end
+
+ context 'given a stand-alone google URL' do
+ let(:text) { 'http://google.com' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="http://google.com"'
+ end
+ end
+
+ context 'given a stand-alone URL with a newer TLD' do
+ let(:text) { 'http://example.gay' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="http://example.gay"'
+ end
+ end
+
+ context 'given a stand-alone IDN URL' do
+ let(:text) { 'https://nic.みんな/' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="https://nic.みんな/"'
+ end
+
+ it 'has display URL' do
+ is_expected.to include 'nic.みんな/'
+ end
+ end
+
+ context 'given a URL with a trailing period' do
+ let(:text) { 'http://www.mcmansionhell.com/post/156408871451/50-states-of-mcmansion-hell-scottsdale-arizona. ' }
+
+ it 'matches the full URL but not the period' do
+ is_expected.to include 'href="http://www.mcmansionhell.com/post/156408871451/50-states-of-mcmansion-hell-scottsdale-arizona"'
+ end
+ end
+
+ context 'given a URL enclosed with parentheses' do
+ let(:text) { '(http://google.com/)' }
+
+ it 'matches the full URL but not the parentheses' do
+ is_expected.to include 'href="http://google.com/"'
+ end
+ end
+
+ context 'given a URL with a trailing exclamation point' do
+ let(:text) { 'http://www.google.com!' }
+
+ it 'matches the full URL but not the exclamation point' do
+ is_expected.to include 'href="http://www.google.com"'
+ end
+ end
+
+ context 'given a URL with a trailing single quote' do
+ let(:text) { "http://www.google.com'" }
+
+ it 'matches the full URL but not the single quote' do
+ is_expected.to include 'href="http://www.google.com"'
+ end
+ end
+
+ context 'given a URL with a trailing angle bracket' do
+ let(:text) { 'http://www.google.com>' }
+
+ it 'matches the full URL but not the angle bracket' do
+ is_expected.to include 'href="http://www.google.com"'
+ end
+ end
+
+ context 'given a URL with a query string' do
+ context 'with escaped unicode character' do
+ let(:text) { 'https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&q=autolink' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&q=autolink"'
+ end
+ end
+
+ context 'with unicode character' do
+ let(:text) { 'https://www.ruby-toolbox.com/search?utf8=✓&q=autolink' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="https://www.ruby-toolbox.com/search?utf8=✓&q=autolink"'
+ end
+ end
+
+ context 'with unicode character at the end' do
+ let(:text) { 'https://www.ruby-toolbox.com/search?utf8=✓' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="https://www.ruby-toolbox.com/search?utf8=✓"'
+ end
+ end
+
+ context 'with escaped and not escaped unicode characters' do
+ let(:text) { 'https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&utf81=✓&q=autolink' }
+
+ it 'preserves escaped unicode characters' do
+ is_expected.to include 'href="https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&utf81=✓&q=autolink"'
+ end
+ end
+ end
+
+ context 'given a URL with parentheses in it' do
+ let(:text) { 'https://en.wikipedia.org/wiki/Diaspora_(software)' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="https://en.wikipedia.org/wiki/Diaspora_(software)"'
+ end
+ end
+
+ context 'given a URL in quotation marks' do
+ let(:text) { '"https://example.com/"' }
+
+ it 'does not match the quotation marks' do
+ is_expected.to include 'href="https://example.com/"'
+ end
+ end
+
+ context 'given a URL in angle brackets' do
+ let(:text) { '' }
+
+ it 'does not match the angle brackets' do
+ is_expected.to include 'href="https://example.com/"'
+ end
+ end
+
+ context 'given a URL with Japanese path string' do
+ let(:text) { 'https://ja.wikipedia.org/wiki/日本' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="https://ja.wikipedia.org/wiki/日本"'
+ end
+ end
+
+ context 'given a URL with Korean path string' do
+ let(:text) { 'https://ko.wikipedia.org/wiki/대한민국' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="https://ko.wikipedia.org/wiki/대한민국"'
+ end
+ end
+
+ context 'given a URL with a full-width space' do
+ let(:text) { 'https://example.com/ abc123' }
+
+ it 'does not match the full-width space' do
+ is_expected.to include 'href="https://example.com/"'
+ end
+ end
+
+ context 'given a URL in Japanese quotation marks' do
+ let(:text) { '「[https://example.org/」' }
+
+ it 'does not match the quotation marks' do
+ is_expected.to include 'href="https://example.org/"'
+ end
+ end
+
+ context 'given a URL with Simplified Chinese path string' do
+ let(:text) { 'https://baike.baidu.com/item/中华人民共和国' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="https://baike.baidu.com/item/中华人民共和国"'
+ end
+ end
+
+ context 'given a URL with Traditional Chinese path string' do
+ let(:text) { 'https://zh.wikipedia.org/wiki/臺灣' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="https://zh.wikipedia.org/wiki/臺灣"'
+ end
+ end
+
+ context 'given a URL containing unsafe code (XSS attack, visible part)' do
+ let(:text) { %q{http://example.com/bb} }
+
+ it 'does not include the HTML in the URL' do
+ is_expected.to include '"http://example.com/b"'
+ end
+
+ it 'escapes the HTML' do
+ is_expected.to include '<del>b</del>'
+ end
+ end
+
+ context 'given a URL containing unsafe code (XSS attack, invisible part)' do
+ let(:text) { %q{http://example.com/blahblahblahblah/a} }
+
+ it 'does not include the HTML in the URL' do
+ is_expected.to include '"http://example.com/blahblahblahblah/a"'
+ end
+
+ it 'escapes the HTML' do
+ is_expected.to include '<script>alert("Hello")</script>'
+ end
+ end
+
+ context 'given text containing HTML code (script tag)' do
+ let(:text) { '' }
+
+ it 'escapes the HTML' do
+ is_expected.to include '
<script>alert("Hello")</script>
'
+ end
+ end
+
+ context 'given text containing HTML (XSS attack)' do
+ let(:text) { %q{} }
+
+ it 'escapes the HTML' do
+ is_expected.to include '
<img src="javascript:alert('XSS');">
'
+ end
+ end
+
+ context 'given an invalid URL' do
+ let(:text) { 'http://www\.google\.com' }
+
+ it 'outputs the raw URL' do
+ is_expected.to eq '
http://www\.google\.com
'
+ end
+ end
+
+ context 'given text containing a hashtag' do
+ let(:text) { '#hashtag' }
+
+ it 'creates a hashtag link' do
+ is_expected.to include '/tags/hashtag" class="mention hashtag" rel="tag">#hashtag'
+ end
+ end
+
+ context 'given text containing a hashtag with Unicode chars' do
+ let(:text) { '#hashtagタグ' }
+
+ it 'creates a hashtag link' do
+ is_expected.to include '/tags/hashtag%E3%82%BF%E3%82%B0" class="mention hashtag" rel="tag">#hashtagタグ'
+ end
+ end
+
+ context 'given text with a stand-alone xmpp: URI' do
+ let(:text) { 'xmpp:user@instance.com' }
+
+ it 'matches the full URI' do
+ is_expected.to include 'href="xmpp:user@instance.com"'
+ end
+ end
+
+ context 'given text with an xmpp: URI with a query-string' do
+ let(:text) { 'please join xmpp:muc@instance.com?join right now' }
+
+ it 'matches the full URI' do
+ is_expected.to include 'href="xmpp:muc@instance.com?join"'
+ end
+ end
+
+ context 'given text containing a magnet: URI' do
+ let(:text) { 'wikipedia gives this example of a magnet uri: magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a' }
+
+ it 'matches the full URI' do
+ is_expected.to include 'href="magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a"'
+ end
+ end
+ end
+end
--
cgit
From 24e78969ae97501aad18595eb3af8c7338a1cb7c Mon Sep 17 00:00:00 2001
From: Eugen Rochko
Date: Sat, 26 Mar 2022 04:02:19 +0100
Subject: Fix typo (#17875)
---
app/serializers/activitypub/actor_serializer.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'app')
diff --git a/app/serializers/activitypub/actor_serializer.rb b/app/serializers/activitypub/actor_serializer.rb
index bd1648348..30f86aae3 100644
--- a/app/serializers/activitypub/actor_serializer.rb
+++ b/app/serializers/activitypub/actor_serializer.rb
@@ -195,7 +195,7 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
end
def value
- html_aware_format(object.value, object.account.value?, with_rel_me: true, with_domains: true, multiline: false)
+ html_aware_format(object.value, object.account.local?, with_rel_me: true, with_domains: true, multiline: false)
end
end
--
cgit
From a4e1830b5f15118bf2532401005376a0c6e896e6 Mon Sep 17 00:00:00 2001
From: mayaeh
Date: Sat, 26 Mar 2022 10:52:51 +0900
Subject: [Glitch] Add a hashtag public link to the trending hashtag page
Port 52813830bee5607332b49bee2916956286ec5dc1 to glitch-soc
Co-authored-by: Claire
Co-authored-by: Eugen Rochko
Co-authored-by: Claire
Signed-off-by: Claire
---
app/javascript/flavours/glitch/components/admin/Counter.js | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
(limited to 'app')
diff --git a/app/javascript/flavours/glitch/components/admin/Counter.js b/app/javascript/flavours/glitch/components/admin/Counter.js
index ecb242950..a4d6cef41 100644
--- a/app/javascript/flavours/glitch/components/admin/Counter.js
+++ b/app/javascript/flavours/glitch/components/admin/Counter.js
@@ -33,6 +33,7 @@ export default class Counter extends React.PureComponent {
label: PropTypes.string.isRequired,
href: PropTypes.string,
params: PropTypes.object,
+ target: PropTypes.string,
};
state = {
@@ -54,7 +55,7 @@ export default class Counter extends React.PureComponent {
}
render () {
- const { label, href } = this.props;
+ const { label, href, target } = this.props;
const { loading, data } = this.state;
let content;
@@ -100,7 +101,7 @@ export default class Counter extends React.PureComponent {
if (href) {
return (
-
+
{inner}
);
--
cgit
From 2c45859ca9076c0b9916922e0be21ff83fc3b143 Mon Sep 17 00:00:00 2001
From: Claire
Date: Mon, 28 Mar 2022 01:17:17 +0200
Subject: Refactor account and status formatting (#17877)
* Refactor status formatting
* Add account formatting helpers
* Remove StatusFormatter
* Fixup
* Fix copied typo
---
app/chewy/statuses_index.rb | 4 +++-
app/helpers/formatting_helper.rb | 12 ++++++++++--
app/lib/feed_manager.rb | 2 +-
app/serializers/activitypub/actor_serializer.rb | 4 ++--
app/serializers/rest/account_serializer.rb | 4 ++--
app/views/accounts/_bio.html.haml | 4 ++--
app/views/admin/accounts/show.html.haml | 4 ++--
app/views/admin/reports/show.html.haml | 2 +-
app/views/directories/index.html.haml | 2 +-
app/views/notification_mailer/_status.text.erb | 2 +-
app/views/notification_mailer/digest.text.erb | 2 +-
11 files changed, 26 insertions(+), 16 deletions(-)
(limited to 'app')
diff --git a/app/chewy/statuses_index.rb b/app/chewy/statuses_index.rb
index d119f7cac..bfd61a048 100644
--- a/app/chewy/statuses_index.rb
+++ b/app/chewy/statuses_index.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
class StatusesIndex < Chewy::Index
+ include FormattingHelper
+
settings index: { refresh_interval: '15m' }, analysis: {
filter: {
english_stop: {
@@ -57,7 +59,7 @@ class StatusesIndex < Chewy::Index
field :id, type: 'long'
field :account_id, type: 'long'
- field :text, type: 'text', value: ->(status) { [status.spoiler_text, PlainTextFormatter.new(status.text, status.local?).to_s].concat(status.ordered_media_attachments.map(&:description)).concat(status.preloadable_poll ? status.preloadable_poll.options : []).join("\n\n") } do
+ field :text, type: 'text', value: ->(status) { [status.spoiler_text, extract_status_plain_text(status)].concat(status.ordered_media_attachments.map(&:description)).concat(status.preloadable_poll ? status.preloadable_poll.options : []).join("\n\n") } do
field :stemmed, type: 'text', analyzer: 'content'
end
diff --git a/app/helpers/formatting_helper.rb b/app/helpers/formatting_helper.rb
index 66e9e1e91..e11156999 100644
--- a/app/helpers/formatting_helper.rb
+++ b/app/helpers/formatting_helper.rb
@@ -9,11 +9,19 @@ module FormattingHelper
TextFormatter.new(text, options).to_s
end
- def extract_plain_text(text, local)
- PlainTextFormatter.new(text, local).to_s
+ def extract_status_plain_text(status)
+ PlainTextFormatter.new(status.text, status.local?).to_s
end
def status_content_format(status)
html_aware_format(status.text, status.local?, preloaded_accounts: [status.account] + (status.respond_to?(:active_mentions) ? status.active_mentions.map(&:account) : []))
end
+
+ def account_bio_format(account)
+ html_aware_format(account.note, account.local?)
+ end
+
+ def account_field_value_format(field, with_rel_me: true)
+ html_aware_format(field.value, field.account.local?, with_rel_me: with_rel_me, with_domains: true, multiline: false)
+ end
end
diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb
index 53d1390d4..709450080 100644
--- a/app/lib/feed_manager.rb
+++ b/app/lib/feed_manager.rb
@@ -446,7 +446,7 @@ class FeedManager
status = status.reblog if status.reblog?
combined_text = [
- extract_plain_text(status.text, status.local?),
+ extract_status_plain_text(status),
status.spoiler_text,
status.preloadable_poll ? status.preloadable_poll.options.join("\n\n") : nil,
status.ordered_media_attachments.map(&:description).join("\n\n"),
diff --git a/app/serializers/activitypub/actor_serializer.rb b/app/serializers/activitypub/actor_serializer.rb
index 30f86aae3..e6dd8040e 100644
--- a/app/serializers/activitypub/actor_serializer.rb
+++ b/app/serializers/activitypub/actor_serializer.rb
@@ -103,7 +103,7 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
end
def summary
- object.suspended? ? '' : html_aware_format(object.note, object.local?)
+ object.suspended? ? '' : account_bio_format(object)
end
def icon
@@ -195,7 +195,7 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
end
def value
- html_aware_format(object.value, object.account.local?, with_rel_me: true, with_domains: true, multiline: false)
+ account_field_value_format(object)
end
end
diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb
index 2f67e06b2..4cf7b253f 100644
--- a/app/serializers/rest/account_serializer.rb
+++ b/app/serializers/rest/account_serializer.rb
@@ -20,7 +20,7 @@ class REST::AccountSerializer < ActiveModel::Serializer
attributes :name, :value, :verified_at
def value
- html_aware_format(object.value, object.account.local?, with_rel_me: true, with_domains: true, multiline: false)
+ account_field_value_format(object)
end
end
@@ -35,7 +35,7 @@ class REST::AccountSerializer < ActiveModel::Serializer
end
def note
- object.suspended? ? '' : html_aware_format(object.note, object.local?)
+ object.suspended? ? '' : account_bio_format(object)
end
def url
diff --git a/app/views/accounts/_bio.html.haml b/app/views/accounts/_bio.html.haml
index df4f9bdb8..e2539b1d4 100644
--- a/app/views/accounts/_bio.html.haml
+++ b/app/views/accounts/_bio.html.haml
@@ -10,12 +10,12 @@
- if field.verified?
%span.verified__mark{ title: t('accounts.link_verified_on', date: l(field.verified_at)) }
= fa_icon 'check'
- = prerender_custom_emojis(html_aware_format(field.value, account.local?, with_rel_me: true, with_domains: true, multiline: false), account.emojis)
+ = prerender_custom_emojis(account_field_value_format(field), account.emojis)
= account_badge(account)
- if account.note.present?
- .account__header__content.emojify= prerender_custom_emojis(html_aware_format(account.note, account.local?), account.emojis)
+ .account__header__content.emojify= prerender_custom_emojis(account_bio_format(account), account.emojis)
.public-account-bio__extra
= t 'accounts.joined', date: l(account.created_at, format: :month)
diff --git a/app/views/admin/accounts/show.html.haml b/app/views/admin/accounts/show.html.haml
index b252f3eac..1230294fe 100644
--- a/app/views/admin/accounts/show.html.haml
+++ b/app/views/admin/accounts/show.html.haml
@@ -21,11 +21,11 @@
- if field.verified?
%span.verified__mark{ title: t('accounts.link_verified_on', date: l(field.verified_at)) }
= fa_icon 'check'
- = prerender_custom_emojis(html_aware_format(field.value, account.local?, with_rel_me: true, with_domains: true, multiline: false), account.emojis)
+ = prerender_custom_emojis(account_field_value_format(field, with_rel_me: false), account.emojis)
- if account.note.present?
%div
- .account__header__content.emojify= prerender_custom_emojis(html_aware_format(account.note, account.local?), account.emojis)
+ .account__header__content.emojify= prerender_custom_emojis(account_bio_format(account), account.emojis)
.dashboard__counters.admin-account-counters
%div
diff --git a/app/views/admin/reports/show.html.haml b/app/views/admin/reports/show.html.haml
index 41fed2efb..cf960565f 100644
--- a/app/views/admin/reports/show.html.haml
+++ b/app/views/admin/reports/show.html.haml
@@ -27,7 +27,7 @@
= fa_icon('lock') if @report.target_account.locked?
- if @report.target_account.note.present?
.account-card__bio.emojify
- = prerender_custom_emojis(html_aware_format(@report.target_account.note, @report.target_account.local?), @report.target_account.emojis)
+ = prerender_custom_emojis(account_bio_format(@report.target_account), @report.target_account.emojis)
.account-card__actions
.account-card__counters
.account-card__counters__item
diff --git a/app/views/directories/index.html.haml b/app/views/directories/index.html.haml
index a032ddb8d..48f8c4bc2 100644
--- a/app/views/directories/index.html.haml
+++ b/app/views/directories/index.html.haml
@@ -34,7 +34,7 @@
= fa_icon('lock') if account.locked?
- if account.note.present?
.account-card__bio.emojify
- = prerender_custom_emojis(html_aware_format(account.note, account.local?), account.emojis)
+ = prerender_custom_emojis(account_bio_format(account), account.emojis)
- else
.flex-spacer
.account-card__actions
diff --git a/app/views/notification_mailer/_status.text.erb b/app/views/notification_mailer/_status.text.erb
index bf6d2b620..1dc8de739 100644
--- a/app/views/notification_mailer/_status.text.erb
+++ b/app/views/notification_mailer/_status.text.erb
@@ -3,6 +3,6 @@
> ----
>
<% end %>
-> <%= raw word_wrap(extract_plain_text(status.text, status.local?), break_sequence: "\n> ") %>
+> <%= raw word_wrap(extract_status_plain_text(status), break_sequence: "\n> ") %>
<%= raw t('application_mailer.view')%> <%= web_url("statuses/#{status.id}") %>
diff --git a/app/views/notification_mailer/digest.text.erb b/app/views/notification_mailer/digest.text.erb
index b767eb9c4..0f84a4ef0 100644
--- a/app/views/notification_mailer/digest.text.erb
+++ b/app/views/notification_mailer/digest.text.erb
@@ -5,7 +5,7 @@
* <%= raw t('notification_mailer.digest.mention', name: notification.from_account.pretty_acct) %>
- <%= raw extract_plain_text(notification.target_status.text, notification.target_status.local?) %>
+ <%= raw extract_status_plain_text(notification.target_status) %>
<%= raw t('application_mailer.view')%> <%= web_url("statuses/#{notification.target_status.id}") %>
<% end %>
--
cgit
From 61cefbebf717326bd6ec3923e67e3702a24a0b24 Mon Sep 17 00:00:00 2001
From: Claire
Date: Mon, 28 Mar 2022 20:51:51 +0200
Subject: Add advanced text formatting back into glitch-soc
---
app/helpers/formatting_helper.rb | 2 +-
app/lib/advanced_text_formatter.rb | 131 +++++++++++++++
app/lib/html_aware_formatter.rb | 6 +-
lib/sanitize_ext/sanitize_config.rb | 57 +++++--
spec/lib/advanced_text_formatter_spec.rb | 274 +++++++++++++++++++++++++++++++
spec/lib/sanitize_config_spec.rb | 18 +-
6 files changed, 459 insertions(+), 29 deletions(-)
create mode 100644 app/lib/advanced_text_formatter.rb
create mode 100644 spec/lib/advanced_text_formatter_spec.rb
(limited to 'app')
diff --git a/app/helpers/formatting_helper.rb b/app/helpers/formatting_helper.rb
index e11156999..2a622ae0b 100644
--- a/app/helpers/formatting_helper.rb
+++ b/app/helpers/formatting_helper.rb
@@ -14,7 +14,7 @@ module FormattingHelper
end
def status_content_format(status)
- html_aware_format(status.text, status.local?, preloaded_accounts: [status.account] + (status.respond_to?(:active_mentions) ? status.active_mentions.map(&:account) : []))
+ html_aware_format(status.text, status.local?, preloaded_accounts: [status.account] + (status.respond_to?(:active_mentions) ? status.active_mentions.map(&:account) : []), content_type: status.content_type)
end
def account_bio_format(account)
diff --git a/app/lib/advanced_text_formatter.rb b/app/lib/advanced_text_formatter.rb
new file mode 100644
index 000000000..5ce87d306
--- /dev/null
+++ b/app/lib/advanced_text_formatter.rb
@@ -0,0 +1,131 @@
+# frozen_string_literal: true
+
+class AdvancedTextFormatter < TextFormatter
+ class HTMLRenderer < Redcarpet::Render::HTML
+ def initialize(options, &block)
+ super(options)
+ @format_link = block
+ end
+
+ def block_code(code, _language)
+ <<~HTML.squish
+
#{h(code).gsub("\n", ' ')}
+ HTML
+ end
+
+ def autolink(link, link_type)
+ return link if link_type == :email
+ @format_link.call(link)
+ end
+ end
+
+ # @param [String] text
+ # @param [Hash] options
+ # @option options [Boolean] :multiline
+ # @option options [Boolean] :with_domains
+ # @option options [Boolean] :with_rel_me
+ # @option options [Array] :preloaded_accounts
+ # @option options [String] :content_type
+ def initialize(text, options = {})
+ content_type = options.delete(:content_type)
+ super(text, options)
+
+ @text = format_markdown(text) if content_type == 'text/markdown'
+ end
+
+ # Differs from TextFormatter by not messing with newline after parsing
+ def to_s
+ return ''.html_safe if text.blank?
+
+ html = rewrite do |entity|
+ if entity[:url]
+ link_to_url(entity)
+ elsif entity[:hashtag]
+ link_to_hashtag(entity)
+ elsif entity[:screen_name]
+ link_to_mention(entity)
+ end
+ end
+
+ html.html_safe # rubocop:disable Rails/OutputSafety
+ end
+
+ # Differs from `TextFormatter` by skipping HTML tags and entities
+ def entities
+ @entities ||= begin
+ gaps = []
+ total_offset = 0
+
+ escaped = text.gsub(/<[^>]*>|[0-9]+;/) do |match|
+ total_offset += match.length - 1
+ end_offset = Regexp.last_match.end(0)
+ gaps << [end_offset - total_offset, total_offset]
+ ' '
+ end
+
+ Extractor.extract_entities_with_indices(escaped, extract_url_without_protocol: false).map do |entity|
+ start_pos, end_pos = entity[:indices]
+ offset_idx = gaps.rindex { |gap| gap.first <= start_pos }
+ offset = offset_idx.nil? ? 0 : gaps[offset_idx].last
+ entity.merge(indices: [start_pos + offset, end_pos + offset])
+ end
+ end
+ end
+
+ private
+
+ # Differs from `TextFormatter` in that it keeps HTML; but it sanitizes at the end to remain safe
+ def rewrite
+ entities.sort_by! do |entity|
+ entity[:indices].first
+ end
+
+ result = ''.dup
+
+ last_index = entities.reduce(0) do |index, entity|
+ indices = entity[:indices]
+ result << text[index...indices.first]
+ result << yield(entity)
+ indices.last
+ end
+
+ result << text[last_index..-1]
+
+ Sanitize.fragment(result, Sanitize::Config::MASTODON_OUTGOING)
+ end
+
+ def format_markdown(html)
+ html = markdown_formatter.render(html)
+ html.delete("\r").delete("\n")
+ end
+
+ def markdown_formatter
+ extensions = {
+ autolink: true,
+ no_intra_emphasis: true,
+ fenced_code_blocks: true,
+ disable_indented_code_blocks: true,
+ strikethrough: true,
+ lax_spacing: true,
+ space_after_headers: true,
+ superscript: true,
+ underline: true,
+ highlight: true,
+ footnotes: false,
+ }
+
+ renderer = HTMLRenderer.new({
+ filter_html: false,
+ escape_html: false,
+ no_images: true,
+ no_styles: true,
+ safe_links_only: true,
+ hard_wrap: true,
+ link_attributes: { target: '_blank', rel: 'nofollow noopener' },
+ }) do |url|
+ link_to_url({ url: url })
+ end
+
+ Redcarpet::Markdown.new(renderer, extensions)
+ end
+end
diff --git a/app/lib/html_aware_formatter.rb b/app/lib/html_aware_formatter.rb
index 64edba09b..7a1cd0340 100644
--- a/app/lib/html_aware_formatter.rb
+++ b/app/lib/html_aware_formatter.rb
@@ -33,6 +33,10 @@ class HtmlAwareFormatter
end
def linkify
- TextFormatter.new(text, options).to_s
+ if %w(text/markdown text/html).include?(@options[:content_type])
+ AdvancedTextFormatter.new(text, options).to_s
+ else
+ TextFormatter.new(text, options).to_s
+ end
end
end
diff --git a/lib/sanitize_ext/sanitize_config.rb b/lib/sanitize_ext/sanitize_config.rb
index ecaec2f84..935e1f4f6 100644
--- a/lib/sanitize_ext/sanitize_config.rb
+++ b/lib/sanitize_ext/sanitize_config.rb
@@ -55,18 +55,6 @@ class Sanitize
end
end
- LINK_REL_TRANSFORMER = lambda do |env|
- return unless env[:node_name] == 'a' and env[:node]['href']
-
- node = env[:node]
-
- rel = (node['rel'] || '').split(' ') & ['tag']
- unless env[:config][:outgoing] && TagManager.instance.local_url?(node['href'])
- rel += ['nofollow', 'noopener', 'noreferrer']
- end
- node['rel'] = rel.join(' ')
- end
-
UNSUPPORTED_HREF_TRANSFORMER = lambda do |env|
return unless env[:node_name] == 'a'
@@ -97,6 +85,7 @@ class Sanitize
add_attributes: {
'a' => {
+ 'rel' => 'nofollow noopener noreferrer',
'target' => '_blank',
},
},
@@ -110,7 +99,6 @@ class Sanitize
CLASS_WHITELIST_TRANSFORMER,
IMG_TAG_TRANSFORMER,
UNSUPPORTED_HREF_TRANSFORMER,
- LINK_REL_TRANSFORMER,
]
)
@@ -135,5 +123,48 @@ class Sanitize
'source' => { 'src' => HTTP_PROTOCOLS }
)
)
+
+ LINK_REL_TRANSFORMER = lambda do |env|
+ return unless env[:node_name] == 'a' && env[:node]['href']
+
+ node = env[:node]
+
+ rel = (node['rel'] || '').split(' ') & ['tag']
+ rel += ['nofollow', 'noopener', 'noreferrer'] unless TagManager.instance.local_url?(node['href'])
+
+ if rel.empty?
+ node['rel']&.delete
+ else
+ node['rel'] = rel.join(' ')
+ end
+ end
+
+ LINK_TARGET_TRANSFORMER = lambda do |env|
+ return unless env[:node_name] == 'a' && env[:node]['href']
+
+ node = env[:node]
+ if node['target'] != '_blank' && TagManager.instance.local_url?(node['href'])
+ node['target']&.delete
+ else
+ node['target'] = '_blank'
+ end
+ end
+
+ MASTODON_OUTGOING ||= freeze_config MASTODON_STRICT.merge(
+ attributes: merge(
+ MASTODON_STRICT[:attributes],
+ 'a' => %w(href rel class title target)
+ ),
+
+ add_attributes: {},
+
+ transformers: [
+ CLASS_WHITELIST_TRANSFORMER,
+ IMG_TAG_TRANSFORMER,
+ UNSUPPORTED_HREF_TRANSFORMER,
+ LINK_REL_TRANSFORMER,
+ LINK_TARGET_TRANSFORMER,
+ ]
+ )
end
end
diff --git a/spec/lib/advanced_text_formatter_spec.rb b/spec/lib/advanced_text_formatter_spec.rb
new file mode 100644
index 000000000..c097b86e1
--- /dev/null
+++ b/spec/lib/advanced_text_formatter_spec.rb
@@ -0,0 +1,274 @@
+require 'rails_helper'
+
+RSpec.describe AdvancedTextFormatter do
+ describe '#to_s' do
+ let(:preloaded_accounts) { nil }
+ let(:content_type) { 'text/markdown' }
+
+ subject { described_class.new(text, preloaded_accounts: preloaded_accounts, content_type: content_type).to_s }
+
+ context 'given a markdown source' do
+ let(:content_type) { 'text/markdown' }
+
+ context 'given text containing plain text' do
+ let(:text) { 'text' }
+
+ it 'paragraphizes the text' do
+ is_expected.to eq '
text
'
+ end
+ end
+
+ context 'given text containing line feeds' do
+ let(:text) { "line\nfeed" }
+
+ it 'removes line feeds' do
+ is_expected.not_to include "\n"
+ end
+ end
+
+ context 'given some inline code using backticks' do
+ let(:text) { 'test `foo` bar' }
+
+ it 'formats code using ' do
+ is_expected.to include 'test foo bar'
+ end
+ end
+
+ context 'given some quote' do
+ let(:text) { "> foo\n\nbar" }
+
+ it 'formats code using ' do
+ is_expected.to include '
foo
'
+ end
+ end
+
+ context 'given text containing linkable mentions' do
+ let(:preloaded_accounts) { [Fabricate(:account, username: 'alice')] }
+ let(:text) { '@alice' }
+
+ it 'creates a mention link' do
+ is_expected.to include '@alice'
+ end
+ end
+
+ context 'given text containing unlinkable mentions' do
+ let(:preloaded_accounts) { [] }
+ let(:text) { '@alice' }
+
+ it 'does not create a mention link' do
+ is_expected.to include '@alice'
+ end
+ end
+
+ context 'given a stand-alone medium URL' do
+ let(:text) { 'https://hackernoon.com/the-power-to-build-communities-a-response-to-mark-zuckerberg-3f2cac9148a4' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="https://hackernoon.com/the-power-to-build-communities-a-response-to-mark-zuckerberg-3f2cac9148a4"'
+ end
+ end
+
+ context 'given a stand-alone google URL' do
+ let(:text) { 'http://google.com' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="http://google.com"'
+ end
+ end
+
+ context 'given a stand-alone URL with a newer TLD' do
+ let(:text) { 'http://example.gay' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="http://example.gay"'
+ end
+ end
+
+ context 'given a stand-alone IDN URL' do
+ let(:text) { 'https://nic.みんな/' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="https://nic.みんな/"'
+ end
+
+ it 'has display URL' do
+ is_expected.to include 'nic.みんな/'
+ end
+ end
+
+ context 'given a URL with a trailing period' do
+ let(:text) { 'http://www.mcmansionhell.com/post/156408871451/50-states-of-mcmansion-hell-scottsdale-arizona. ' }
+
+ it 'matches the full URL but not the period' do
+ is_expected.to include 'href="http://www.mcmansionhell.com/post/156408871451/50-states-of-mcmansion-hell-scottsdale-arizona"'
+ end
+ end
+
+ context 'given a URL enclosed with parentheses' do
+ let(:text) { '(http://google.com/)' }
+
+ it 'matches the full URL but not the parentheses' do
+ is_expected.to include 'href="http://google.com/"'
+ end
+ end
+
+ context 'given a URL with a trailing exclamation point' do
+ let(:text) { 'http://www.google.com!' }
+
+ it 'matches the full URL but not the exclamation point' do
+ is_expected.to include 'href="http://www.google.com"'
+ end
+ end
+
+ context 'given a URL with a trailing single quote' do
+ let(:text) { "http://www.google.com'" }
+
+ it 'matches the full URL but not the single quote' do
+ is_expected.to include 'href="http://www.google.com"'
+ end
+ end
+ end
+
+ context 'given a URL with a trailing angle bracket' do
+ let(:text) { 'http://www.google.com>' }
+
+ it 'matches the full URL but not the angle bracket' do
+ is_expected.to include 'href="http://www.google.com"'
+ end
+ end
+
+ context 'given a URL with a query string' do
+ context 'with escaped unicode character' do
+ let(:text) { 'https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&q=autolink' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&q=autolink"'
+ end
+ end
+
+ context 'with unicode character' do
+ let(:text) { 'https://www.ruby-toolbox.com/search?utf8=✓&q=autolink' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="https://www.ruby-toolbox.com/search?utf8=✓&q=autolink"'
+ end
+ end
+
+ context 'with unicode character at the end' do
+ let(:text) { 'https://www.ruby-toolbox.com/search?utf8=✓' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="https://www.ruby-toolbox.com/search?utf8=✓"'
+ end
+ end
+
+ context 'with escaped and not escaped unicode characters' do
+ let(:text) { 'https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&utf81=✓&q=autolink' }
+
+ it 'preserves escaped unicode characters' do
+ is_expected.to include 'href="https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&utf81=✓&q=autolink"'
+ end
+ end
+
+ context 'given a URL with parentheses in it' do
+ let(:text) { 'https://en.wikipedia.org/wiki/Diaspora_(software)' }
+
+ it 'matches the full URL' do
+ is_expected.to include 'href="https://en.wikipedia.org/wiki/Diaspora_(software)"'
+ end
+ end
+
+ context 'given a URL in quotation marks' do
+ let(:text) { '"https://example.com/"' }
+
+ it 'does not match the quotation marks' do
+ is_expected.to include 'href="https://example.com/"'
+ end
+ end
+
+ context 'given a URL in angle brackets' do
+ let(:text) { '' }
+
+ it 'does not match the angle brackets' do
+ is_expected.to include 'href="https://example.com/"'
+ end
+ end
+
+ context 'given a URL containing unsafe code (XSS attack, invisible part)' do
+ let(:text) { %q{http://example.com/blahblahblahblah/a} }
+
+ it 'does not include the HTML in the URL' do
+ is_expected.to include '"http://example.com/blahblahblahblah/a"'
+ end
+
+ it 'does not include a script tag' do
+ is_expected.to_not include '' }
+
+ it 'does not include a script tag' do
+ is_expected.to_not include '