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

attrs.mode can return an invalid string #17

Open
ayuhito opened this issue Aug 29, 2024 · 1 comment · May be fixed by #18
Open

attrs.mode can return an invalid string #17

ayuhito opened this issue Aug 29, 2024 · 1 comment · May be fixed by #18
Labels
bug Something isn't working

Comments

@ayuhito
Copy link

ayuhito commented Aug 29, 2024

Environment

Node.js 18
nanotar: 0.1.1

Reproduction

Example attributes:

attrs: {
      mode: '000666 ',
      uid: 765,
      gid: 24,
      mtime: 1647357732,
      user: '',
      group: ''
    }

Describe the bug

There's a trailing space in attrs.mode: mode: '000666 '. This isn't the fault of createTar, but the tar file I'm reading is slightly malformed and seems to return this.

Technically, this wouldn't be a problem if we were returning octal literals instead. Then anything from 0644 to 0000644 or more would be valid. For now I'm calling trim on the string when calling fs.writeFile(..., mode: file.attrs?.mode?.trim()), but this feels very very very wrong to do so in practice.

Maybe an API change to return numbers instead of a string might feel more intuitive to the end user who is likely to be using fs anyways?

Additional context

No response

Logs

No response

@ayuhito ayuhito added the bug Something isn't working label Aug 29, 2024
@kricsleo
Copy link

Same issue here, I would suggest adding a trim internally:

const mode = _readString(buffer, offset + 100, 8);

-    const mode = _readString(buffer, offset + 100, 8);
+    const mode = _readString(buffer, offset + 100, 8).trim();

@kricsleo kricsleo linked a pull request Aug 30, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants