[Melbourne-pm] Handling line ending characters
benhare at gmail.com
Thu Nov 1 20:11:24 PDT 2012
all you should need on the Perl side is something like:
$str =~ s/[\r\n]*$//;
also see perldoc -f chomp
other common cleaning functions are:
$str =~ s/^\s*//;
and / or
$str =~ s/\s*$//;
some for modules have functions to do this sort of thing for you also.
On 2 November 2012 13:29, Stephen Edmonds <stephen.edmonds at monash.edu> wrote:
> I was wondering what techniques people use to handle getting different line
> ending characters from various sources.
> The specific example I have in mind is a field on a web form. The field uses
> jQuery to check client side that the input is less than 100 characters, and
> then we check again on the server side in perl. If the form is submitted
> from Windows, then you get two characters per line ending. jQuery converts
> these to a single character it may think that the text is ok at 99
> characters, but the two characters per line ending are actually submitted,
> so our server side check may think it is (for eg) 103 characters and error.
> It is an edge case where client side validation doesn't match the server
> side validation.
> One common solution seems to be to go to a regex with \r?\n, \015?\012, etc,
> while another option is to use Encode::Newlines (which does do regexes
> internally, but maintaining that is not our concern)
> A further question is do we convert the line endings for the validation and
> still store the originally submitted text, or do we store a converted
> How do people handle this?
> Stephen Edmonds
> Technical Lead Applications
> Production manager for my.monash, Blackboard and Google Apps
> eSolutions, Monash University
> Melbourne-pm mailing list
> Melbourne-pm at pm.org
Benjamin J. Hare
Professional Web Development Services
Email: ben at benhare.com
More information about the Melbourne-pm