Skip to content

Commit

Permalink
Item13385: Allow \| vbar escapes in form values
Browse files Browse the repository at this point in the history
Forms are documented as supporting backslash in the initial values
definition.  The table parser does not support \|,  and a simple
escape of \| breaks things.

Since the Foswiki::Form uses the generic Tables::Parser, this
change detects when parsing a form,  and handles the \| escaped vbars
only in the initial values column.
  • Loading branch information
gac410 committed Jun 22, 2015
1 parent 159d3a8 commit 4cd29cf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
3 changes: 2 additions & 1 deletion core/data/System/DataForms.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1434484983" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1434988360" format="1.1" version="1"}%
%META:TOPICPARENT{name="UserDocumentationCategory"}%
%STARTINCLUDE%
---+!! Data Forms
Expand Down Expand Up @@ -229,6 +229,7 @@ For checkboxes, radio buttons and dropdown lists: predefined input to select fro
* Field values can also be generated through a %SYSTEMWEB%.FormattedSearch, which must yield a suitable table as the result.
* Macros in the initial values of a form definition get expanded when the form definition is loaded.
* If you want to use a =|= character in the initial values field, you have to precede it with a backslash, thus: =\|=.
* =\|= escaping is __only active in the Values column._ It is not usable elsewhere. Use =&vbar;= or =|= in other columns.
* You can use =<nop>= to prevent macros from being expanded.
* The [[%SYSTEMWEB%.FormatTokens][Format tokens]] can be used to prevent expansion of other characters.

Expand Down
42 changes: 30 additions & 12 deletions core/lib/Foswiki/Tables/Parser.pm
Expand Up @@ -100,6 +100,9 @@ a table (i.e. not verbatim or literal lines).
sub parse {
my ( $text, $dispatch ) = @_;

# SMELL: Should this be a flag in the call, rathern than caller magic
my $procform = ( (caller)[0] eq 'Foswiki::Form' );

my $in_table = 0;
my %scope = ( verbatim => 0, literal => 0, include => 0 );
my $openRow;
Expand Down Expand Up @@ -186,29 +189,44 @@ sub parse {

if ( length($line) ) {

# See Item13385 for why this is commented out
#$line =~ s/\\\|/\007/g; # protect \| from split

# Expand comments again after we split
my @cols =
map { _rewrite( $_, \@comments ) }
map { s/\007/|/g; $_ }
split( /\|/, $line, -1 );

# Note use of LIMIT=-1 on the split so we don't lose
# empty columns

foreach my $col (@cols) {
my ( $prec, $text, $postc, $ish ) = split_cell($col);
if ($ish) {
print STDERR "TH '$prec', '$text', '$postc'\n"
my $rowlen = scalar @cols;
for ( my $i = 0 ; $i < $rowlen ; $i++ ) {
if ( $procform
&& $i == 3
&& ( substr( $cols[$i], -1 ) eq '\\' )
&& $i < $rowlen )
{
# Form definitions allow use of \| escapes in the initial values colunn - column 4
# So this code removes the "splits" from within the initial values
# But only when processing a form. See Item13385
print STDERR "Merging Form values column.\n"
if TRACE;
&$dispatch( 'th', $prec, $text, $postc );
chop $cols[$i];
$cols[$i] .= '|' . splice( @cols, $i + 1, 1 );
$rowlen--;
redo;
}
else {
print STDERR "TD '$prec', '$text', '$postc'\n"
if TRACE;
&$dispatch( 'td', $prec, $text, $postc );
my ( $prec, $text, $postc, $ish ) =
split_cell( $cols[$i] );
if ($ish) {
print STDERR "TH '$prec', '$text', '$postc'\n"
if TRACE;
&$dispatch( 'th', $prec, $text, $postc );
}
else {
print STDERR "TD '$prec', '$text', '$postc'\n"
if TRACE;
&$dispatch( 'td', $prec, $text, $postc );
}
}
}
}
Expand Down

1 comment on commit 4cd29cf

@cdot
Copy link
Contributor

@cdot cdot commented on 4cd29cf Jun 23, 2015

Choose a reason for hiding this comment

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

Good fix George, thanks!

Please sign in to comment.