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

Bug - Leading Whitespace On Stream In #53

Merged
merged 1 commit into from
Mar 4, 2020

Conversation

jnhyatt
Copy link
Contributor

@jnhyatt jnhyatt commented Mar 4, 2020

There is an issue where leading whitespace in an input stream buffer causes a path to be invalid.

To reproduce:

fs::path path;
std::istringstream ss("line text.txt");
std::string directive;
ss >> directive >> path;

std::ifstream fileIn(path); // tries to open " text.txt" (leading space, nonexistent file)
assert (fileIn); // assertion fails when using ghc::filesystem

See a compiling example here. This was tested using MSVC 16.4.5 and g++ 9.1.0. In both configurations, std::filesystem behaves as expected (run std-fs in the root directory) where ghc::filesystem returns a path with a leading space and fails to properly parse when handed to std::ifstream (run alt-fs in the root directory).

The fix simply streams in the first character when testing for a quote character. This causes the operation to respect the current skipws flag. Using std::basic_istream::get() will ignore the skipws flag and simply read in the first character (if there is leading whitespace, a whitespace character). If the skipws flag is set in the istream, both std::filesystem and ghc::filesystem read in the whitespace character and fail the assertion.

@gulrak
Copy link
Owner

gulrak commented Mar 4, 2020

Nice catch, thank you!

@gulrak gulrak merged commit bd30737 into gulrak:master Mar 4, 2020
@gulrak gulrak added this to the v1.3.1 milestone Mar 7, 2020
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.

None yet

2 participants