Page MenuHomePhabricator

Display errors/nonprintable characters more clearly when warning users about invalid data inputs
Closed, ResolvedPublic

Assigned To
Authored By
huangsj
Sep 4 2016, 7:23 AM
Referenced Files
F1801466: ldap_register.png
Sep 4 2016, 3:11 PM
F1801462: pasted_file
Sep 4 2016, 3:00 PM
F1801458: import_from_ldap_error.png
Sep 4 2016, 2:55 PM
F1801456: import_from_ldap.png
Sep 4 2016, 2:55 PM

Description

Version Info:
phabricator 9a52492f1b2c0449410d8935d35fb71ed562e9a3 (Fri, Aug 26)
arcanist 9e82ef979e8148c43b9b8439025d505b1219e213 (Thu, Aug 25)
phutil 5fd1af8b4f2b9631e2ceb06bd88d21f2416123c2 (Thu, Aug 25)

Reproduction steps:

Click "Import From LDAP" in USER ADMINISTRATOR.
Fill in the required fields with valid credentials and LDAP query "objectClass=inetOrgPerson".
Click "Search" to let Phabricator list available users.
Mark column "Import?" checkbox in corresponding rows checked
Click Import button to import users

Expected result:

All selected users should be imported and can be viewed in Approval Queue

Actual result:

Phabricator tells me that Email addresses should be in the form 'user@domain.com'.

In fact, the import fails because my users have email address with 163.com suffix or their username contains underscore, if I change suffix to domains with letters and remove all underscores, import succeeds.

Email address like mike@163.com or huang_123@163.com are valid and should not be rejected during LDAP import.

Event Timeline

What is the exact error message you received?

I am not able to reproduce any issue with these email address formats. Do you have any suggestions for how I can do things differently?

For example, I want to import
readonly_user readonly_user@company.com readonly_user readonly_user

And Error message is

Failed to add readonly_user
Email addresses should be in the form 'user@domain.com'. The maximum length of an email address is 128 character(s).

import_from_ldap.png (1×2 px, 131 KB)

import_from_ldap_error.png (1×1 px, 126 KB)

These are valid email addresses in Phabricator. I don't have any other ideas why you're running to an error.

pasted_file (208×602 px, 30 KB)

Do these fail for you during single person invites as well or only during LDAP?

I just tried again. It seems that I miss the latter part of the error message.

It turns out that the real cause of the error is "The maximum length of an email address is 128 character(s)."

I edited email address in my LDAP server by adding a space and then remove the space, then Phabricator successfully imported users.

I didn't realize it could be a configuration issue in LDAP server

Hmm, yeah I wonder if it's anything we can detect on our end. Doesn't sound very common though.

New Info.

Users can register during Login but Email field is empty.

ldap_register.png (450×1 px, 44 KB)

To correct my previous post.
The real cause of the error is Email addresses should be in the form 'user@domain.com'.

I manage to export user profile from LDAP server and check letter by letter and found out that when these users are imported to LDAP server from csv files, an additional space is added at the end of email address, so when I see readonly_user@company.com it is actually "readonly_user@company.com\0x20".

Maybe it is ok for the import from LDAP module to trim leading and ending spaces.

chad renamed this task from Fail to import users from LDAP if LDAP user's email address has suffix @163.com or username contains underscore to Trim spaces when importing emails from LDAP.Sep 4 2016, 8:56 PM
chad triaged this task as Wishlist priority.

I don't think we should actually trim() the address -- if you have bad data in LDAP, you should fix it.

We could conceivably introduce some function like reveal_invisibles($string) which takes in input like " " and returns "<space>", then print an error message like:

Email addresses should be in the form "user@domain.com", but address "us<NULL>er@<tab>domain.com<space>" is not.

Of course, then we run into junk like this:

File names should consist of only lowercase letters, but filename "<Literal Open Angle Bracket>title<Literal Close Angle Bracket>My First Web Page" does not.

I'm not entirely sure this would ultimately be more clear.

epriestley renamed this task from Trim spaces when importing emails from LDAP to Display errors/nonprintable characters more clearly when warning users about invalid data inputs.Sep 5 2016, 3:01 PM

The goal is to provide an easy way for us to print messages like this:

Input data "X" is not valid. It must conform to <some rules>.

...and have errors with the ruleset that are caused by unprintable characters (leading or trailing spaces, control characters, stray tabs, etc) be immediately obvious in the output so that users can identify them at a glance and we can clearly point them out if given a screenshot or copy/paste of the message.

To do this:

  • Write a PHUIInvisibleStringView() or similar, perhaps with a far better and more evocative name.
  • PHUIRemarkupView might be a similar, somewhat-simple view to follow.
  • It should accept a string and return an HTML description of that string, but with unprintable characters rendered visible.
  • Write a unit test for it I guess? Maybe have a mode that just returns raw data instead of HTML for unit tests and eventual possible use in email/API/chat/etc., where HTML may not be available.
  • Use this view in the code described above.

For example, if the input string is a b\x00c\x01d\te\nf, the output might be something like this:

array(
  'a',
  phutil_tag('span', array('class' => 'invisible-special'), '<space>'),
  'b',
  phutil_tag('span', array('class' => 'invisible-special'), '<null>'),
  'c',
  phutil_tag('span', array('class' => 'invisible-special'), '<0x01>'),
  'd',
  phutil_tag('span', array('class' => 'invisible-special'), '<tab>'),
  'e',
  phutil_tag('span', array('class' => 'invisible-special'), '<newline>'),
  'f'
);