Skip to content

Commit

Permalink
Change status length limit to 8192 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
aurieh authored and Joshix-1 committed Oct 10, 2023
1 parent 030a427 commit 98aa508
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Expand Up @@ -100,7 +100,7 @@ class ComposeForm extends ImmutablePureComponent {
const fulltext = this.getFulltextForCharacterCounting();
const isOnlyWhitespace = fulltext.length !== 0 && fulltext.trim().length === 0;

return !(isSubmitting || isUploading || isChangingUpload || length(fulltext) > 500 || (isOnlyWhitespace && !anyMedia));
return !(isSubmitting || isUploading || isChangingUpload || length(fulltext) > 8192 || (isOnlyWhitespace && !anyMedia));
};

handleSubmit = (e) => {
Expand Down Expand Up @@ -297,7 +297,7 @@ class ComposeForm extends ImmutablePureComponent {
</div>

<div className='character-counter__wrapper'>
<CharacterCounter max={500} text={this.getFulltextForCharacterCounting()} />
<CharacterCounter max={8192} text={this.getFulltextForCharacterCounting()} />
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/validators/status_length_validator.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class StatusLengthValidator < ActiveModel::Validator
MAX_CHARS = 500
MAX_CHARS = 8192
URL_PLACEHOLDER_CHARS = 23
URL_PLACEHOLDER = 'x' * 23

Expand Down
17 changes: 9 additions & 8 deletions spec/validators/status_length_validator_spec.rb
Expand Up @@ -16,20 +16,20 @@
expect(status).to_not receive(:errors)
end

it 'adds an error when content warning is over 500 characters' do
status = instance_double(Status, spoiler_text: 'a' * 520, text: '', errors: activemodel_errors, local?: true, reblog?: false)
it 'adds an error when content warning is over 8192 characters' do
status = instance_double(Status, spoiler_text: 'a' * 8193, text: '', errors: activemodel_errors, local?: true, reblog?: false)
subject.validate(status)
expect(status.errors).to have_received(:add)
end

it 'adds an error when text is over 500 characters' do
status = instance_double(Status, spoiler_text: '', text: 'a' * 520, errors: activemodel_errors, local?: true, reblog?: false)
it 'adds an error when text is over 8192 characters' do
status = instance_double(Status, spoiler_text: '', text: 'a' * 9000, errors: activemodel_errors, local?: true, reblog?: false)
subject.validate(status)
expect(status.errors).to have_received(:add)
end

it 'adds an error when text and content warning are over 500 characters total' do
status = instance_double(Status, spoiler_text: 'a' * 250, text: 'b' * 251, errors: activemodel_errors, local?: true, reblog?: false)
it 'adds an error when text and content warning are over 8192 characters total' do
status = instance_double(Status, spoiler_text: 'a' * 4096, text: 'b' * 4097, errors: activemodel_errors, local?: true, reblog?: false)
subject.validate(status)
expect(status.errors).to have_received(:add)
end
Expand All @@ -51,8 +51,9 @@
end

it 'does not count overly long URLs as 23 characters flat' do
text = "http://example.com/valid?#{'#foo?' * 1000}"
text = "http://example.com/valid?#{'#foo?' * 8192}"
status = instance_double(Status, spoiler_text: '', text: text, errors: activemodel_errors, local?: true, reblog?: false)

subject.validate(status)
expect(status.errors).to have_received(:add)
end
Expand All @@ -66,7 +67,7 @@
end

it 'does count both parts of remote usernames for overly long domains' do
text = "@alice@#{'b' * 500}.com"
text = "@alice@#{'b' * 8192}.com"
status = instance_double(Status, spoiler_text: '', text: text, errors: activemodel_errors, local?: true, reblog?: false)

subject.validate(status)
Expand Down

0 comments on commit 98aa508

Please sign in to comment.