Download & Extend

Problem with uploading sIFR font files with hyphens in the filename

Project:Dynamic Rendering
Version:6.x-1.x-dev
Component:sIFR plugin
Category:bug report
Priority:normal
Assigned:Unassigned
Status:reviewed & tested by the community

Issue Summary

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.

Comments

#1

Title:Problem with uploading sIFR font files with hyphens» Problem with uploading sIFR font files with hyphens in the filename

#2

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

Status:active» needs review

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

#4

Status:needs review» reviewed & tested by the community

I know it's an old issue, but just ran into this on a dev site (site-dev). I ran the patch, cleared both the render and site caches, and all is well. Changing to tested.