Bug 105838

Summary: [PATCH] JavaScript (and HTML) files containing "use strict" are misdetected as Perl files
Product: shared-mime-info Reporter: Dwayne Litzenberger <dlitz>
Component: freedesktop.org.xmlAssignee: Shared Mime Info group <shared_mime_info>
Status: RESOLVED MOVED QA Contact:
Severity: normal    
Priority: medium Keywords: patch
Version: unspecified   
Hardware: Other   
OS: All   
See Also: http://bugs.debian.org/887709
Whiteboard:
i915 platform: i915 features:
Attachments: patch: Perl detection: Don't match ECMAScript "use strict" syntax

Description Dwayne Litzenberger 2018-04-01 02:21:01 UTC
HTML and JavaScript files are sometimes being misdetected as Perl files, due to the following match rule for application/x-perl:

    <match type="string" value="use strict" offset="0:256"/>

This is too broad.  It incorrectly matches against ECMAScript's strict-mode syntax[1], which can look like one of the following lines (including quotes and semicolon):
 
    "use strict";
    'use strict';

This seems to have been introduced in commit a6bdb6a198f8f9fe4153f72e5b4d10e1b5057c3e (shared-mime-info 1.2), which was related to bug 63612.

As a solution, I suggest to replace the above match rule with rules that will match the Perl syntax without matching the quote-surrounded JavaScript syntax:

    <match type="string" value="use strict;" offset="0:256"/>
    <match type="string" value="use strict " offset="0:256"/>

A patch will be attached to this bug.

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
Comment 1 Dwayne Litzenberger 2018-04-01 02:30:15 UTC
Created attachment 138469 [details] [review]
patch: Perl detection: Don't match ECMAScript "use strict" syntax
Comment 2 GitLab Migration User 2018-10-13 10:41:09 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/xdg/shared-mime-info/issues/80.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.