1673481736.FILE5_44-15-ga2756aa5.improve-javascript-detection-fc-stegerman.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. Subject: Improve JavaScript detection (FC Stegerman)
  2. Origin: FILE5_44-15-ga2756aa5 <https://github.com/file/file/commit/FILE5_44-15-ga2756aa5>
  3. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  4. Date: Thu Jan 12 00:02:16 2023 +0000
  5. --- a/magic/Magdir/javascript
  6. +++ b/magic/Magdir/javascript
  7. @@ -3,18 +3,68 @@
  8. # $File: javascript,v 1.4 2022/09/02 08:08:17 christos Exp $
  9. # javascript: magic for javascript and node.js scripts.
  10. #
  11. -0 string/w #!/bin/node Node.js script text executable
  12. +0 string/tw #!/bin/node Node.js script executable
  13. !:mime application/javascript
  14. -0 string/w #!/usr/bin/node Node.js script text executable
  15. +0 string/tw #!/usr/bin/node Node.js script executable
  16. !:mime application/javascript
  17. -0 string/w #!/bin/nodejs Node.js script text executable
  18. +0 string/tw #!/bin/nodejs Node.js script executable
  19. !:mime application/javascript
  20. -0 string/w #!/usr/bin/nodejs Node.js script text executable
  21. -!:mime application/javascript
  22. -0 string #!/usr/bin/env\ node Node.js script text executable
  23. -!:mime application/javascript
  24. -0 string #!/usr/bin/env\ nodejs Node.js script text executable
  25. +0 string/tw #!/usr/bin/nodejs Node.js script executable
  26. !:mime application/javascript
  27. +0 string/t #!/usr/bin/env\ node Node.js script executable
  28. +!:mime application/javascript
  29. +0 string/t #!/usr/bin/env\ nodejs Node.js script executable
  30. +!:mime application/javascript
  31. +
  32. +# JavaScript
  33. +# The strength is increased to beat the C++ & HTML rules
  34. +0 search "use\x20strict" JavaScript source
  35. +!:strength +30
  36. +!:mime application/javascript
  37. +!:ext js
  38. +0 search 'use\x20strict' JavaScript source
  39. +!:strength +30
  40. +!:mime application/javascript
  41. +!:ext js
  42. +0 regex module(\\.|\\[["'])exports.*= JavaScript source
  43. +!:strength +30
  44. +!:mime application/javascript
  45. +!:ext js
  46. +0 regex \^(const|var|let).*=.*require\\( JavaScript source
  47. +!:strength +30
  48. +!:mime application/javascript
  49. +!:ext js
  50. +0 regex \^export\x20(function|class|default|const|var|let|async)\x20 JavaScript source
  51. +!:strength +30
  52. +!:mime application/javascript
  53. +!:ext js
  54. +0 regex \\((async\x20)?function[(\x20] JavaScript source
  55. +!:strength +30
  56. +!:mime application/javascript
  57. +!:ext js
  58. +0 regex \^(import|export).*\x20from\x20 JavaScript source
  59. +!:strength +30
  60. +!:mime application/javascript
  61. +!:ext js
  62. +0 regex \^(import|export)\x20["']\\./ JavaScript source
  63. +!:strength +30
  64. +!:mime application/javascript
  65. +!:ext js
  66. +0 regex \^require\\(["'] JavaScript source
  67. +!:strength +30
  68. +!:mime application/javascript
  69. +!:ext js
  70. +0 regex typeof.*[!=]== JavaScript source
  71. +!:strength +30
  72. +!:mime application/javascript
  73. +!:ext js
  74. +
  75. +# React Native minified JavaScript
  76. +0 search/128 __BUNDLE_START_TIME__= React Native minified JavaScript
  77. +!:strength +30
  78. +!:mime application/javascript
  79. +!:ext bundle/jsbundle
  80. +
  81. # Hermes by Facebook https://hermesengine.dev/
  82. # https://github.com/facebook/hermes/blob/master/include/hermes/\
  83. # BCGen/HBC/BytecodeFileFormat.h#L24
  84. --- a/magic/Magdir/sgml
  85. +++ b/magic/Magdir/sgml
  86. @@ -50,6 +50,16 @@
  87. !:mime text/html
  88. !:strength + 5
  89. +# avoid misdetection as JavaScript
  90. +0 string/cWt \<!doctype\ html HTML document text
  91. +!:mime text/html
  92. +0 string/ct \<html> HTML document text
  93. +!:mime text/html
  94. +0 string/ct \<!--
  95. +>&0 search/4096/cWt \<!doctype\ html HTML document text
  96. +>&0 search/4096/ct \<html> HTML document text
  97. +!:mime text/html
  98. +
  99. # SVG document
  100. # https://www.w3.org/TR/SVG/single-page.html
  101. 0 search/4096/cWbt \<!doctype\ svg SVG XML document