This patch fixes the infamous problem in htdig 3.1.3 of mangling URL parameters that contain bare ampersands (&), and not converting & entities in URLs. --- htdig-3.1.3/htdig/HTML.cc.orig Wed Sep 22 11:18:40 1999 +++ htdig-3.1.3/htdig/HTML.cc Thu Oct 14 15:08:24 1999 @@ -1114,7 +1114,15 @@ HTML::transSGML(char *str) while (*text) { if (*text == '&') - convert << SGMLEntities::translateAndUpdate(text); + { + if (strncmp((char *)text, "&", 5) == 0) + { + // We MUST convert these in URLs, regardless of translate_amp. + convert << '&'; + text += 5; + } else + convert << SGMLEntities::translateAndUpdate(text); + } else convert << *text++; } --- htdig-3.1.3/htdig/SGMLEntities.cc.orig Wed Sep 22 11:18:41 1999 +++ htdig-3.1.3/htdig/SGMLEntities.cc Thu Oct 14 15:08:31 1999 @@ -280,5 +280,11 @@ SGMLEntities::translateAndUpdate(unsigne if (*entityStart == ';') entityStart++; // A final ';' is used up. - return translate(entity); + unsigned char e = translate(entity); + if (e == ' ' && strncmp((char *)orig, " ", 4) != 0) + { + entityStart = orig + 1; // Catch unrecognized entities... + return '&'; + } + return e; }