Ticket #2 (closed enhancement: fixed)

Opened 5 years ago

Last modified 4 years ago

Grabcode handler

Reported by: dartar Owned by: DarTar
Priority: normal Milestone: 1.1.6.2
Component: formatters Version: 1.1.6.1
Severity: normal Keywords:
Cc:

Description (last modified by DarTar) (diff)

If time/effort allows, I'd like to see this one: it's already proved to be a "selling point". Stylesheet rules need to be improved though. --JW

 http://wikkawiki.org/GrabCodeHandler

[migrated from  http://wikkawiki.org/AdminDevelopmentDiscussions]

Updates

The code committed to the repository as of [49], [50] and [51] adds a further option to the code block syntax, allowing users to specify a filename for the code block, e.g.:

%%(php;22;myfile.php) ... %%

If a file name (like myfile.php) is specified:

  • a code block header is generated with the filename;
  • the filename is added to the title of the grab button;
  • the filename is posted as through a form hidden field so it can be used as a name for the file generated by the grabcode handler.

A (configurable) extension (default: .txt) is appended to the filename by the grabcode handler to prevent the browser from directly running potential malicious code on download.

Change History

Changed 5 years ago by dartar

  • owner changed from dartar to unassigned

Changed 4 years ago by DarTar

  • owner changed from unassigned to DarTar
  • status changed from new to assigned
  • version changed from 1.1.6.0 to 1.1.6.1
  • milestone changed from 1.1.7 to 1.1.6.2

Changed 4 years ago by DarTar

Code committed in [49] [50] and [51]. Keep ticket open until code has been further checked for stability/security.

Changed 4 years ago by DarTar

  • description modified (diff)

Changed 4 years ago by DarTar

Debugging: the regex used in the wakka formatter at line 214 for the optional filename value produces an incorrect page parsing:

source:trunk/formatters/wakka.php#L214

Changed 4 years ago by DarTar

  • component changed from handlers to formatters

Here's the correct reference:

source:trunk/formatters/wakka.php?rev=L214#L214

the regex pattern is:

"/^\((.+?)(;([0-9]+))?(;(.*))??\)(.*)$/s"

The tricky part is the third bracketed subpattern for the (optional) filename . The idea is that I want at this stage to match anything before the closing ")" and check later whether this is a valid filename. The problem is that using \w is too restrictive. I'll play a little bit with this. Feedback welcome.

Changed 4 years ago by DarTar

Regex replaced with the following (credits: DotMG)

/^\(([^;]+)(;(\d*?))?(;([^\)\x01-\x1f\*\?\"<>\|]*)(.*))?\)(.*)$/s

Code change committed as [56]

Now the formatter parses correctly code blocks and uses filename if valid.

Changed 4 years ago by DarTar

Mahefa, while testing the formatter I discovered that the new parser generates multiple instances of the same codeblock in a page containing at least two codeblocks. See what happens in the default FormattingRule.

(keeping ticket open)

Changed 4 years ago by DarTar

Previous issued solved by reinitializing the $output variable on line 210 (credits: DotMG - merci!).

Patch committed as [60].

Should we make the filename option configurable from wikka.config.php (much as line numbering)?

Changed 4 years ago by DarTar

Note that FormattingRules must be updated to take into account the filename option.

Changed 4 years ago by DarTar

  • status changed from assigned to closed
  • resolution set to fixed
  • description modified (diff)

Updated FormattingRules in [66] (both as a default page for fresh installs and as a revision for upgraders).

Changed 4 years ago by DarTar

  • status changed from closed to reopened
  • resolution fixed deleted

Reopening ticket - there is a bug in the codeblock parser. When using round brackets in the code, the regex fail to correctly parse the geshi parameters. I'll try to fix this.

Changed 4 years ago by DarTar

Mahefa, why don't we just drop the $invalid match ? I don't see any use of extracting it - I think we should just extract the filename as everything before the closing bracket. If it's not valid, then filename won't be used in the codeblock header and in the grabcode form.

Changed 4 years ago by NilsLindenberg

What perhaps could be done is breaking down the regepx into smaller parts to have more oversight, like it was done in the color action.

Changed 4 years ago by DarTar

Fixed issue with code containing brackets - [101] 1.1.6.2 ready for alpha.

Changed 4 years ago by DarTar

  • status changed from reopened to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.