这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@Spiral90210
Copy link
Contributor

Fixes #151

@Spiral90210
Copy link
Contributor Author

Any thoughts on accepting this PR? Fixes a problem we see with real world mail, yes it technically shouldn't be happening, but as with most things email there's always something writing mail that does so badly. Always.

@emersion
Copy link
Owner

Can we maybe replace ' ' and '\t' with '\n' which already gets ignored by encoding/base64? That way no need to deal with count/offset changes etc.

@Spiral90210
Copy link
Contributor Author

It's actually based on the code from base64.go, just extended to account for these extra characters - I figured extending that would make more sense than wrapping/filtering twice.

Here's the original code from the standard library:

type newlineFilteringReader struct {
	wrapped io.Reader
}

func (r *newlineFilteringReader) Read(p []byte) (int, error) {
	n, err := r.wrapped.Read(p)
	for n > 0 {
		offset := 0
		for i, b := range p[:n] {
			if b != '\r' && b != '\n' {
				if i != offset {
					p[offset] = b
				}
				offset++
			}
		}
		if offset > 0 {
			return offset, err
		}
		// Previous buffer entirely whitespace, read again
		n, err = r.wrapped.Read(p)
	}
	return n, err
}

@Spiral90210
Copy link
Contributor Author

Can we maybe replace ' ' and '\t' with '\n' which already gets ignored by encoding/base64? That way no need to deal with count/offset changes etc.

Done - yes it is a lot more simple, thanks for the suggestion!

@emersion
Copy link
Owner

I figured extending that would make more sense than wrapping/filtering twice.

Hm but the wrapping is done internally by the standard library anyways right?

Copy link
Owner

@emersion emersion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@emersion emersion merged commit 21cb40c into emersion:master May 11, 2022
@emersion
Copy link
Owner

Thanks!

@Spiral90210
Copy link
Contributor Author

I figured extending that would make more sense than wrapping/filtering twice.

Hm but the wrapping is done internally by the standard library anyways right?

Yup 🙄 clearly I was just satisfied with it working and then just went to live in fantasy land for a while!

@Spiral90210 Spiral90210 deleted the feature/151_handle_incorrect_fws_in_b64_part branch May 11, 2022 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Does not correctly ignore 'bad' base64 whitespace characters RFC-2045

2 participants