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

can't decode base64-encoded data with linebreaks #39

Open
a1021101652 opened this issue Jan 12, 2023 · 1 comment
Open

can't decode base64-encoded data with linebreaks #39

a1021101652 opened this issue Jan 12, 2023 · 1 comment

Comments

@a1021101652
Copy link

Can't remove '\n' directly at here ,because of the character not in standard base64-encoded data ,but i don't know better solution

issue at :base64.cpp:171
`
if (remove_linebreaks) {

   std::string copy(encoded_string);

   copy.erase(std::remove(copy.begin(), copy.end(), '\n'), copy.end());

   return base64_decode(copy, false);
}`
@Satancito
Copy link

Windows linefeed is \r\n
Old MacOS linefeed is \r. New MacOS versions is \n
Linux linefeed is \n.

To avoid errors on decode, try removing all spacing chars \r, \n, \t, \v, \f, \000

Example

#include <string>
#include <iostream>
#include <vector>

void removeSubstrings(std::string& str, const std::vector<std::string>& toRemove) {
    for (const auto& subStr : toRemove) {
        size_t pos;
        while ((pos = str.find(subStr)) != std::string::npos) {
            str.erase(pos, subStr.length());
        }
    }
}

int main() {
    std::string str = "String\n with\t text\r that must be removed 😑😀!!!";
    std::vector<std::string> toRemove = {"\r", "\n", "\t", "😑"};

    removeSubstrings(str, toRemove);

    std::cout << "Result: " << str << std::endl;

    return 0;
}

Output

Result: String with text that must be removed 😀!!!

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

No branches or pull requests

2 participants