Forward port of 51850 from release25-maint branch.

As mentioned on python-dev, reverting patch #1504333 because it introduced
an infinite loop in rev 47154.

This patch also adds a test to prevent the regression.
diff --git a/Misc/NEWS b/Misc/NEWS
index 34c3e7c..6f12bce 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -40,6 +40,8 @@
 Library
 -------
 
+- Reverted patch #1504333 to sgmllib because it introduced an infinite loop.
+
 - Patch #1553314: Fix the inspect.py slowdown that was hurting IPython & SAGE
   by adding smarter caching in inspect.getmodule()