Skip to content

DecoderReader does not respect with_decode_allow_trailing_bits #236

@chanced

Description

@chanced

Before you file an issue

  • Did you read the docs? yes
  • Did you read the README? yes

The problem

  • DecoderReader does not respect with_decode_allow_trailing_bits. Decoding input with a trailing newline results in the error Invalid byte 10, offset 224.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6f1faeb41bee1e2b3bab8b5a510dd9f3

use base64::{
    engine::{DecodePaddingMode,  GeneralPurpose, GeneralPurposeConfig},
    read::DecoderReader,
};
use std::io::Read;

fn main() {
    let engine = GeneralPurpose::new(
        &base64::alphabet::STANDARD,
        GeneralPurposeConfig::new()
            .with_encode_padding(false)
            .with_decode_padding_mode(DecodePaddingMode::Indifferent)
            .with_decode_allow_trailing_bits(true),
    );
    let input = b"aGVsbG8gd29ybGQ=\n";
    let mut r = DecoderReader::new(input.as_slice(), &engine);
    let mut data = vec![];
    r.read_to_end(&mut data).unwrap();
}

This is somewhat problematic with a CLI which can pipe back into itself. Adding a newline at the end of the output avoids the shell partial line indicator %.

How I, the issue filer, am going to help solve it

  • I'm willing to implement it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions