Teammates: Instructor: enroll students: leading spaces in email should be trimmed internally

Created on 17 Oct 2017  路  7Comments  路  Source: TEAMMATES/teammates

v5.112:
A user reported that enrollment fails if there is a leading space in front of the email address.
image

p.Medium

All 7 comments

Yup, it's the same case. Turns out it's not a regular space char; even excel trim could not remove it. Looks like it's %C2%A0 (non-breaking char in UTF-8?).

C2 A0 indeed corresponds to the non-breaking space (link). Relevant part of the code:
https://github.com/TEAMMATES/teammates/blob/a446786d53aa235b020d6dfdea1ca64562a595d6/src/main/java/teammates/common/datatransfer/StudentAttributesFactory.java#L96-L109

The 5 fields (team, name, email, comment, section) depend on StringHelper.removeExtraSpace to remove leading/trailing spaces; however, the method does not trim those and hence, they may potentially contain leading/trailing non-breaking spaces. It's easy to implement a fix (link); however, what should the correct behaviour be? That kind of space is a special character, and while it's probably illegal for email addresses, I'm wondering if there are situations where users might genuinely want them to be part of the input for team/name/comment/section.

I suspect leading/trailing nbsp is guaranteed to be an unintended error. What do you think?

I don't know if we should handle all types of whitespaces but if we do I would prefer we use something like from Guava to make sure we are handling the whitespaces correctly.

CharMatcher

Also, Comparison of several definitions of "whitespace", extracted from Guava docs.

@LiHaoTan your suggestion is precisely why I suggested StringHelper to be a facade class.

One more case reported today.

Was this page helpful?
0 / 5 - 0 ratings