Expand refs constraints to include valid characters

Fixes #4831, #4865, #4932
Merge pull request #4968 from pdf/issue_4831

Expand refs constraints to include valid characters