Skip to content

Commit 8e8a23e

Browse files
committed
Fix #2187
1 parent 890a2dd commit 8e8a23e

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

httplib.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5440,17 +5440,30 @@ inline bool parse_accept_header(const std::string &s,
54405440
return;
54415441
}
54425442

5443-
try {
5444-
accept_entry.quality = std::stod(quality_str);
5445-
// Check if quality is in valid range [0.0, 1.0]
5446-
if (accept_entry.quality < 0.0 || accept_entry.quality > 1.0) {
5443+
#ifdef CPPHTTPLIB_NO_EXCEPTIONS
5444+
{
5445+
std::istringstream iss(quality_str);
5446+
iss >> accept_entry.quality;
5447+
5448+
// Check if conversion was successful and entire string was consumed
5449+
if (iss.fail() || !iss.eof()) {
54475450
has_invalid_entry = true;
54485451
return;
54495452
}
5453+
}
5454+
#else
5455+
try {
5456+
accept_entry.quality = std::stod(quality_str);
54505457
} catch (...) {
54515458
has_invalid_entry = true;
54525459
return;
54535460
}
5461+
#endif
5462+
// Check if quality is in valid range [0.0, 1.0]
5463+
if (accept_entry.quality < 0.0 || accept_entry.quality > 1.0) {
5464+
has_invalid_entry = true;
5465+
return;
5466+
}
54545467
} else {
54555468
// No quality parameter, use entire entry as media type
54565469
accept_entry.media_type = entry;

0 commit comments

Comments
 (0)