Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] application/javascript files treated as binary file #396

Closed
acourtneybrown opened this issue Aug 5, 2023 · 5 comments
Closed

[bug] application/javascript files treated as binary file #396

acourtneybrown opened this issue Aug 5, 2023 · 5 comments
Labels

Comments

@acourtneybrown
Copy link

Dotdrop version (and git commit if run from source): v1.13.0
Using dotdrop: from Homebrew

Describe the bug

The _handle_file method in templategen.py treats files with mime-type application/javascript as a binary file, thus only copying it directly vs. running the file through the templating engine. I'm uncertain if this recent bug is due to a change in dotdrop or the underlying magic library, as my setup had previously worked with version of dotdrop prior to 1.13.0_1 (from Homebrew), but now I see the same incorrect behavior with 1.13.0 & 1.12.13

Steps to Reproduce

Steps to reproduce the behavior:

  1. Create a dotfile with media-type application/javascript which also has template directives & has the template property either true or inherited true.
  2. Run dotdrop install on the file
  3. Notice that the resulting file still contains the template directives
  4. See error

Expected behavior

The file should be run through the templating engine & the template directives should not appear in the resulting output file.

Additional information

From acourtneybrown/dotfiles:

  f_finicky.js:
    src: finicky.js
    dst: ~/.finicky.js

which uses finicky.js (from the same repo) containing template directives like:

    {%@@ if personal @@%}
    {
      match: [
        finicky.matchHostnames([
          "govzw.com",

          /nytimes.com/,
          /wsj.com/,
        ]),
        /^https:\/\/github.com\/{{@@ github_account @@}}\/.*$/,
      ],
      browser: "Safari"
    },
    {
      match: ({ opener }) => {
        // finicky.log(opener.bundleId);
        return opener.bundleId
          && (opener.bundleId === "com.agilebits.onepassword7" || opener.bundleId === "com.1password.1password")
      },
      browser: "Safari"
    },
    {%@@ endif @@%}

Dotdrop's execution with the debug logs (--verbose)

$ dotdrop install --verbose f_finicky.js
...

contains output showing the misidentification of the application/javascript file as not text:

[DEBUG][dotdrop.templategen._handle_file] using "magic" for filetype identification
[DEBUG][dotdrop.templategen._handle_file] filetype "/Users/adambrown/.dotfiles/dotfiles/finicky.js": application/javascript
[DEBUG][dotdrop.templategen._handle_file] is text "/Users/adambrown/.dotfiles/dotfiles/finicky.js": False
@deadc0de6
Copy link
Owner

Thanks for reporting this.
Dotdrop will handle files as text as long as their mime type contains text, json or empty.

I tried running the finicky.js file through file and python-magic with different outputs depending on OS/versions. Most of time text/plain is returned but I also got application/javascript.

Even though application/javascript is obsolete (and thus shouldn't happen), I will add an exception for the following mime types so that those files will get handle as text:

  • ecmascript
  • javascript

deadc0de6 added a commit that referenced this issue Aug 5, 2023
@deadc0de6
Copy link
Owner

The above commit should fix it for you. Could you test dotdrop from the master branch and let me know if that does it for you?

@acourtneybrown
Copy link
Author

Yeah, the change above ensures that dotdrop processes the Javascript file through the template engine. Thanks for the quick help.

@deadc0de6
Copy link
Owner

@acourtneybrown awesome!

Thanks for your help. I'll release a new version on pypi ASAP and will ping you when done.

@deadc0de6
Copy link
Owner

@acourtneybrown new version 1.13.2 is available on pypi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants