Problem with uploading sIFR font files with hyphens in the filename

cocoloco - May 14, 2009 - 13:56
Project:Dynamic Rendering
Version:6.x-1.x-dev
Component:sIFR plugin
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

Hello,

There seems to be a problem when uploading sIFR font files with hyphens in the name. It looks like it creates a JavaScript variable based on the name of the font, and the hyphens cause an error since this is not an allowed character in JS variable names.

Example:
======================
Error: missing ; before statement
Source File: /sites/default/files/render/sifr3-rules.js?E
Line: 2, Column: 6
Source Code:
var sitesdefaultfilesrendersifr-tradegothic-boldswf = { src: '/sites/default/files/render/sifr-tradegothic-bold.swf' };

My recommendation would be to sanitize the font file name after upload and either delete anything not [A-Za-z0-9_] or replace it with an underscore.

I'd love to help, but I've never submitted a patch before....after this project is done I will give it a try (I'm on a tight deadline at the moment).

Thank you very much for providing this module.

#1

cocoloco - May 14, 2009 - 14:00
Title:Problem with uploading sIFR font files with hyphens» Problem with uploading sIFR font files with hyphens in the filename

#2

xurizaemon - August 16, 2009 - 22:16

The hyphenated font file name is probably fine. I stumbled on this one too, because the generated rule and then JS variable are also hyphenated, and the issue is that a JS variable named "dog-cat" is actually "dog minus cat".

var sitesdefaultfilesrendersifr-arial-narrowswf = { src: '/sites/default/files/render/sifr-arial-narrow.swf' };
sIFR.activate(sitesdefaultfilesrendersifr-arial-narrowswf);

It's just this line in sifr3.inc which shouldn't contain a hyphen -

      // Build JavaScript-safe variable name.
      $rule['fontname'] = preg_replace('@[^a-zA-Z0-9_-]@', '', $rule['font']);

Patch attached.

AttachmentSize
462544-hyphenated-font-file-names.patch 763 bytes

#3

xurizaemon - August 16, 2009 - 22:17
Status:active» needs review

always forget this bit ... gotta write myself a userscript for that

 
 

Drupal is a registered trademark of Dries Buytaert.