Skip to content

Refactor ContentDisposition type check #34573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,23 @@ private ContentDisposition(@Nullable String type, @Nullable String name, @Nullab
* @since 5.3
*/
public boolean isAttachment() {
return (this.type != null && this.type.equalsIgnoreCase("attachment"));
return isDispositionType("attachment");
}

/**
* Return whether the {@link #getType() type} is {@literal "form-data"}.
* @since 5.3
*/
public boolean isFormData() {
return (this.type != null && this.type.equalsIgnoreCase("form-data"));
return isDispositionType("form-data");
}

/**
* Return whether the {@link #getType() type} is {@literal "inline"}.
* @since 5.3
*/
public boolean isInline() {
return (this.type != null && this.type.equalsIgnoreCase("inline"));
return isDispositionType("inline");
}

/**
Expand Down Expand Up @@ -555,6 +555,10 @@ private static char hexDigit(int b) {
return Character.toUpperCase(Character.forDigit(b & 0xF, 16));
}

private boolean isDispositionType(String type) {
return this.type != null && this.type.equalsIgnoreCase(type);
}


/**
* A mutable builder for {@code ContentDisposition}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,34 @@ void parseFormattedWithQuestionMark() {
.isEqualTo(filename);
}

@Test
void isAttachment(){
ContentDisposition attachment = ContentDisposition.attachment().build();
ContentDisposition inline = ContentDisposition.inline().build();
ContentDisposition formData = ContentDisposition.formData().build();
assertThat(attachment.isAttachment()).isTrue();
assertThat(inline.isAttachment()).isFalse();
assertThat(formData.isAttachment()).isFalse();
}

@Test
void isInline(){
ContentDisposition attachment = ContentDisposition.attachment().build();
ContentDisposition inline = ContentDisposition.inline().build();
ContentDisposition formData = ContentDisposition.formData().build();
assertThat(attachment.isInline()).isFalse();
assertThat(inline.isInline()).isTrue();
assertThat(formData.isInline()).isFalse();
}

@Test
void isFormData(){
ContentDisposition attachment = ContentDisposition.attachment().build();
ContentDisposition inline = ContentDisposition.inline().build();
ContentDisposition formData = ContentDisposition.formData().build();
assertThat(attachment.isFormData()).isFalse();
assertThat(inline.isFormData()).isFalse();
assertThat(formData.isFormData()).isTrue();
}

}