Skip to content

fix(#641): trim member full name before persistence - #798

Open
IrynaLypnyk wants to merge 5 commits into
Women-Coding-Community:mainfrom
IrynaLypnyk:fix/641-trim-member-names
Open

IrynaLypnyk wants to merge 5 commits into
Women-Coding-Community:mainfrom
IrynaLypnyk:fix/641-trim-member-names

Conversation

@IrynaLypnyk

Copy link
Copy Markdown
Contributor

Description

Trims leading and trailing whitespace from member full names before saving them to the database.

The fix is applied at the shared member persistence layer, so it covers Member, Mentor, and Mentee create/update flows.

The admin member create form was also updated to trim fullName before submission and to reject whitespace-only names.

Related Issue

Fixes #641

Change Type

  • Bug Fix
  • New Feature
  • Code Refactor
  • Documentation
  • Test
  • Other

Screenshots

Not applicable — no visual UI changes.

Pull request checklist

Please check if your PR fulfills the following requirements:

  • [x ] I checked and followed the contributor guide
  • [x ] I have tested my changes locally.

@sonarqubecloud

Copy link
Copy Markdown

@Sowmiya07

Sowmiya07 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

@IrynaLypnyk I am going to hold this off for a couple more days. I am going to collate all the fields that require this fix and send them to you. As a follow-up, we also need a script to fix this in the backend.

I will assign this to myself for now, I will add more info and assign back to you.

@Sowmiya07 Sowmiya07 assigned Sowmiya07 and IrynaLypnyk and unassigned Sowmiya07 Oct 9, 2026
UPDATE_SQL,
member.getFullName(),
StringUtils.trim(member.getFullName()),
member.getSlackDisplayName(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding this "StringUtils.trim()" this should be handled at the time of deserialization. And then for the fields we do not need the Trim can have custom annotation say - NoTrim can be used if we do not want to strip the leading/trailing spaces.

Suggested change
member.getSlackDisplayName(),
1. An opt-out annotation
package com.wcc.platform.deserializers;
/** Marks a String property that must be deserialized as-is, without trimming (e.g. passwords). */
@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface NoTrim {}
2. A trimming String deserializer
package com.wcc.platform.deserializers;
/**
* Strips leading and trailing whitespace from every JSON string value, unless the target
* property is annotated with {@link NoTrim}.
*/
public class TrimmingStringDeserializer extends StdScalarDeserializer<String>
implements ContextualDeserializer {
public TrimmingStringDeserializer() {
super(String.class);
}
@Override
public String deserialize(final JsonParser parser, final DeserializationContext context)
throws IOException {
final String value = StringDeserializer.instance.deserialize(parser, context);
return value == null ? null : value.strip();
}
@Override
public JsonDeserializer<?> createContextual(
final DeserializationContext context, final BeanProperty property) {
if (property != null && property.getAnnotation(NoTrim.class) != null) {
return StringDeserializer.instance;
}
return this;
}
}
It uses strip() rather than trim() because strip() also removes Unicode whitespace, such as a non-breaking space pasted from a document.
3. Register it once in ObjectMapperConfig
new SimpleModule()
.addDeserializer(String.class, new TrimmingStringDeserializer())
// ...existing serializers/deserializers
4. Opt out where needed
public record LoginRequest(@NotBlank String email, @NoTrim @NotBlank String password) {}
After this, fullName, email, city and every other string, including items inside List<String>, arrive already trimmed. The mappers don't need to do anything, and @NotBlank checks the trimmed value.
Eg -
- Password fields need @NoTrim. They're in AuthController (login), PasswordResetService request types, and SeedUser. Each one missed would silently change what the user typed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Sowmiya07 and @goelsonali

@Sowmiya07, you mentioned collecting the other fields that need trimming. @goelsonali, you suggested a global trimming deserializer.

That approach would trim JSON string values across the API, with explicit opt-outs for passwords and other whitespace-sensitive fields, so it broadens the scope beyond member names.

Could you confirm whether you’d prefer to keep this PR focused on member fields and introduce the global deserializer in a follow-up, or include it here?

In the meantime, I’ve addressed Slack display name trimming and validation in the admin form.

@sonarqubecloud

sonarqubecloud Bot commented Nov 1, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Extra space in full name

3 participants