Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions args.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -3922,8 +3922,22 @@ namespace args
return false;
}

ss >> std::ws;
return ss.peek() == std::char_traits<char>::eof();
// Check for trailing garbage by attempting to extract any remaining characters.
// Do not use 'ss >> std::ws' followed by peek(), as std::ws can set failbit
// on EOF, causing false rejection of valid input.
char extra = '\0';
ss >> std::ws >> extra;
// If extraction succeeded, there's trailing garbage (return false).
// If extraction failed due to EOF only (goodbit after ws extraction), it's valid (return true).
// If extraction failed for other reasons, it's invalid (return false).
if (ss.fail())
{
// Clear the failbit to check if EOF is the only issue
ss.clear(ss.rdstate() & ~std::ios::failbit);
return ss.eof();
}
// Extraction succeeded, meaning there's trailing garbage
return false;
}

template <typename T>
Expand Down
Loading