Bug 105838 - [PATCH] JavaScript (and HTML) files containing "use strict" are misdetected as Perl files
Summary: [PATCH] JavaScript (and HTML) files containing "use strict" are misdetected a...
Status: RESOLVED MOVED
Alias: None
Product: shared-mime-info
Classification: Unclassified
Component: freedesktop.org.xml (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Shared Mime Info group
QA Contact:
URL:
Whiteboard:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2018-04-01 02:21 UTC by Dwayne Litzenberger
Modified: 2018-10-13 10:41 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
patch: Perl detection: Don't match ECMAScript "use strict" syntax (2.86 KB, patch)
2018-04-01 02:30 UTC, Dwayne Litzenberger
Details | Splinter Review

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.