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

Attached files with # at the beginning of filename are renamed into *.png #3389

Open
neroignis opened this issue Dec 5, 2019 · 2 comments
Open
Labels
bug 🐛 Issue concerns a bug. level 1 ❕ A bug that caused minor damage: App is still usable, but minor features might not work.

Comments

@neroignis
Copy link

neroignis commented Dec 5, 2019

Current behavior

When dragging a word-document with a "#" at the beginning of the filename into the editor, a link is created.
The file copied to the attachments folder is now an *.png file and opens in image viewer.
The windows image viewer is confused.

Expected behavior

When dragging a word-document with a "#" at the beginning of the filename into the editor, a link to the word-file is created and the file isn't renamed to .png.

Steps to reproduce

  1. Create a new markdown note
  2. Drag a word-file into the editor
  3. Look at the link

Environment

  • Version : Boostnote 0.13.0
  • OS Version and name: Windows 10 Pro 64-Bit-Version (10.0. Build 18362)
@joaofl
Copy link

joaofl commented Dec 6, 2019

Attaching a file without any extension also causes the attachment to be renamed to .png
(Running it on Ubuntu 19.10)

@Flexo013 Flexo013 added the needs investigation 🔬 Issue requires further investigation to locate or narrow down the problem. label Dec 6, 2019
@Giagnus64
Copy link

Giagnus64 commented Jan 25, 2020

I did some research and found the problem in this section of code
Lines 148-177 attachmentManagment.js

function copyAttachment (sourceFilePath, storageKey, noteKey, useRandomName = true) {
  return new Promise((resolve, reject) => {
    if (!sourceFilePath) {
      reject('sourceFilePath has to be given')
    }

    if (!storageKey) {
      reject('storageKey has to be given')
    }

    if (!noteKey) {
      reject('noteKey has to be given')
    }

    try {
      const isBase64 = typeof sourceFilePath === 'object' && sourceFilePath.type === 'base64'
      if (!isBase64 && !fs.existsSync(sourceFilePath)) {
        return reject('source file does not exist')
      }

      const sourcePath = sourceFilePath.sourceFilePath || sourceFilePath
      const sourceURL = url.parse(/^\w+:\/\//.test(sourcePath) ? sourcePath : 'file:///' + sourcePath)

      let destinationName  
      if (useRandomName) {
        destinationName = `${uniqueSlug()}${path.extname(sourceURL.pathname) || '.png'}` 
        debugger
      } else {
        destinationName = path.basename(sourceURL.pathname)
      }

When a "#" character is used, the sourceURL object is parsed incorrectly, causing the destinationName to use the ".png" extension name. This is due to the url.parse method having built in security to ignore the "#" character as a delimiter nodejs/node-v0.x-archive#711

@Flexo013 Flexo013 added bug 🐛 Issue concerns a bug. level 1 ❕ A bug that caused minor damage: App is still usable, but minor features might not work. and removed needs investigation 🔬 Issue requires further investigation to locate or narrow down the problem. labels Jan 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Issue concerns a bug. level 1 ❕ A bug that caused minor damage: App is still usable, but minor features might not work.
Projects
None yet
Development

No branches or pull requests

4 participants