From: Claire Date: Tue, 2 Mar 2021 11:06:58 +0000 (+0100) Subject: Merge branch 'main' into glitch-soc/merge-upstream X-Git-Url: https://git.xn--scling-oua.cat.family/?a=commitdiff_plain;h=d8fdbb054e30f6e8e505bce63e5f150bf117cd8e;p=mastodon.git Merge branch 'main' into glitch-soc/merge-upstream Conflicts: - `app/validators/status_length_validator.rb`: Upstream changes too close to glitch-soc MAX_CHARS changes, but not a real conflict. Applied upstream changes. - `package.json`: glitch-soc-only dependency textually too close to a dependency updated upstream, not a real conflict. Applied upstream changes. --- d8fdbb054e30f6e8e505bce63e5f150bf117cd8e diff --cc app/validators/status_length_validator.rb index 92ee5e643,b56c5a321..dcbc4a41a --- a/app/validators/status_length_validator.rb +++ b/app/validators/status_length_validator.rb @@@ -1,7 -1,14 +1,14 @@@ # frozen_string_literal: true class StatusLengthValidator < ActiveModel::Validator - MAX_CHARS = 500 + MAX_CHARS = (ENV['MAX_TOOT_CHARS'] || 500).to_i + URL_PATTERN = %r{ + (?: + (#{Twitter::TwitterText::Regex[:valid_url_preceding_chars]}) + (#{FetchLinkCardService::URL_PATTERN}) + ) + }iox + URL_PLACEHOLDER = "\1#{'x' * 23}" def validate(status) return unless status.local? && !status.reblog? diff --cc package.json index e81844964,bff9db566..1cb3b8650 --- a/package.json +++ b/package.json @@@ -72,8 -71,7 +72,8 @@@ "@gamestdio/websocket": "^0.3.2", "@github/webauthn-json": "^0.5.7", "@rails/ujs": "^6.1.3", - "array-includes": "^3.1.2", + "array-includes": "^3.1.3", + "atrament": "0.2.4", "arrow-key-navigation": "^1.2.0", "autoprefixer": "^9.8.6", "axios": "^0.21.1", diff --cc spec/validators/status_length_validator_spec.rb index 62791cd2f,bef3f29f5..643ea6d22 --- a/spec/validators/status_length_validator_spec.rb +++ b/spec/validators/status_length_validator_spec.rb @@@ -47,10 -42,16 +47,18 @@@ describe StatusLengthValidator d expect(status.errors).to_not have_received(:add) end + it 'does not count non-autolinkable URLs as 23 characters flat' do + text = ('a' * 476) + "http://#{'b' * 30}.com/example" + status = double(spoiler_text: '', text: text, errors: double(add: nil), local?: true, reblog?: false) + + subject.validate(status) + expect(status.errors).to have_received(:add) + end + it 'counts only the front part of remote usernames' do - text = ('a' * 475) + " @alice@#{'b' * 30}.com" + username = '@alice' + chars = StatusLengthValidator::MAX_CHARS - 1 - username.length + text = ('a' * 475) + " #{username}@#{'b' * 30}.com" status = double(spoiler_text: '', text: text, errors: double(add: nil), local?: true, reblog?: false) subject.validate(status)