Skip to content

Commit

Permalink
Item15012: remove time tokens in attach format
Browse files Browse the repository at this point in the history
this hurts more than it helps: wiki apps in ATTACHEDFILELINKFORMAT are unconditionally
piped through formatTime() causing all sorts of unintentional changes
  • Loading branch information
MichaelDaum committed Mar 1, 2021
1 parent f07256b commit cc0f53b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 44 deletions.
34 changes: 0 additions & 34 deletions UnitTestContrib/test/unit/UploadScriptTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -603,40 +603,6 @@ qr/^ \* \[\[%ATTACHURL%\/Flappadoodle\.txt\]\[Flappadoodle\.txt\]\]: Educate t
$text
);

# Test a formatted link using standard escapes, and time tokens.
$result = $this->do_upload(
'Flappadoodle.txt',
$data,
undef,
hidefile => 1,
filecomment => 'Wikiworld',
createlink => 1,
linkformat =>
'$n |$year-$mo $wday|Effort $lt-- |[[%ATTACHURL%/$name][%ICON{$fileext}% $name]]| received from $comment |',
changeproperties => 1
);
$this->assert_matches( qr/^Status: 302/ms, $result );
( $meta, $text ) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );

my $format = '$year-$mo $wday';
my $formatted = Foswiki::Time::formatTime( time, $format );

if ( $this->check_dependency('Foswiki,<,1.2') ) {
$this->assert_matches(
qr#^\$n\Q |$format|Effort \E\$\Qlt-- |[[%ATTACHURL%/Flappadoodle.txt][%ICON{\E\$\Qfileext}% Flappadoodle.txt]]| received from Wikiworld |\E#ms,
$text
);
}
else {

# Item5935 added time and standard tokens to the attachment link text to version 1.2
$this->assert_matches(
qr#^\Q |$formatted|Effort <-- |[[%ATTACHURL%/Flappadoodle.txt][%ICON{txt}% Flappadoodle.txt]]| received from Wikiworld |\E#ms,
$text
);
}

return;
}

Expand Down
8 changes: 4 additions & 4 deletions core/data/System/FileAttachment.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1590419979" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1614616935" format="1.1" version="1"}%
%META:TOPICPARENT{name="UserDocumentationCategory"}%
%STARTINCLUDE%
---+ File Attachments
Expand Down Expand Up @@ -85,10 +85,10 @@ Attachment names are stored directly in the server native file system, so filena
* =$filename=: the name of the file
* =$fileext=: the filename extension (string following the last period, if present) or an empty string.
* =$fileurl=: URL encoded version of the filename
* =$filetime: the time in epoch seconds when the attachment was last modified
* =$comment=: the file comment from the upload dialog
* =$size=: the filesize (=%<nop>ATTACHEDIMAGEFORMAT%= only)
* Any standard [[FormatTokens][formatting tokens]]: =$n=, =$comma=, =$lt=, etc.
* Any standard [[VarGMTIME][time format specifiers]]: =$year=, =$hours=, etc.
* =$name=: (deprecated, should no longer be used)

---++ Downloading files
Expand Down Expand Up @@ -262,5 +262,5 @@ Describe the file so other people know what it is.
---
*Related Topics:* UserDocumentationCategory

%META:FILEATTACHMENT{name="Sample.txt" attr="" comment="Just a sample" date="1590419979" size="30" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="Smile.gif" attr="" comment="Smiley face" date="1590419979" size="94" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="Sample.txt" attr="" comment="Just a sample" date="1614616935" size="30" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="Smile.gif" attr="" comment="Smiley face" date="1614616935" size="94" user="ProjectContributor" version="1"}%
10 changes: 4 additions & 6 deletions core/lib/Foswiki/Attach.pm
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,12 @@ sub getAttachmentLink {

# I18N: Site specified %ATTACHEDIMAGEFORMAT% or %ATTACHEDFILELINKFORMAT%,
# ensure that filename is URL encoded - first $name must be URL.
$fileLink =~ s/\$name/$attName/; # deprecated
$fileLink =~ s/\$name/$attName/; # deprecated, see Item1814
$fileLink =~ s/\$name/$attName/g; # deprecated
$fileLink =~ s/\$name/$attName/g; # deprecated, see Item1814
$fileLink =~ s/\$filename/$attName/g;
$fileLink =~ s/\$fileurl/$attName/g;
$fileLink =~ s/\$fileext/$fileExt/;
$fileLink =~ s/\$fileext/$fileExt/g;
$fileLink =~ s/\$filetime/$fileTime/g;

# Expand \t and \n early (only in the format, not
# in the comment) - TWikibug:Item4581
Expand All @@ -426,9 +427,6 @@ sub getAttachmentLink {
$fileLink =~ s/\$comment/$fileComment/g;
$fileLink =~ s/\$size/$imgSize/g;
$fileLink =~ s/([^\n])$/$1\n/;

require Foswiki::Time;
$fileLink = Foswiki::Time::formatTime( $fileTime, $fileLink );
$fileLink = Foswiki::expandStandardEscapes($fileLink);

return $fileLink;
Expand Down

0 comments on commit cc0f53b

Please sign in to comment.