Skip to content

HttpHeaders.setContentDispositionFormData should ignore empty filename #25769

@npimentel

Description

@npimentel

When a Multipart Form request is used with an empty string as Filename, a "No Filename" exception is thrown. Can an empty String check be added to prevent the code from failing in empty string scenarios?

public void setContentDispositionFormData(String name, @Nullable String filename) {
		Assert.notNull(name, "Name must not be null");
		ContentDisposition.Builder disposition = ContentDisposition.builder("form-data").name(name);
		 if (filename != null) {  // Add Empty String check here, don't let through if empty String
			disposition.filename(filename);    // calls method below
		}
		setContentDisposition(disposition.build());
	}

@Override
		public Builder filename(String filename) {
			Assert.hasText(filename, "No filename");  // Assertion Fails since the the filename does not have text
			this.filename = filename;
			return this;
		}

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions