From 11929b45cb7e30995e9d779fc8f484734a5da98b Mon Sep 17 00:00:00 2001 From: "alecf%netscape.com" Date: Mon, 25 Jun 2001 21:44:26 +0000 Subject: [PATCH] fix for bug 83489 - fix the url-duping code in session history so that we don't throw exceptions on badly formed urls r=dougt, sr=blizzard, a=chofmann git-svn-id: svn://10.0.0.236/trunk@97879 18797224-902f-48f8-a5cc-f745e15eee43 --- .../resources/content/sessionHistoryUI.js | 65 +++++++++++++------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/mozilla/xpfe/browser/resources/content/sessionHistoryUI.js b/mozilla/xpfe/browser/resources/content/sessionHistoryUI.js index a6585a27aaf..f45257e3aca 100644 --- a/mozilla/xpfe/browser/resources/content/sessionHistoryUI.js +++ b/mozilla/xpfe/browser/resources/content/sessionHistoryUI.js @@ -136,33 +136,56 @@ function addToUrlbarHistory() var unused = { }; var scheme = ioService.extractScheme(urlToAdd, unused, unused); } catch(e) { - urlToAdd = "http://" + urlToAdd; + urlToAdd = "http://" + urlToAdd; + } + + try { + var uriToAdd = ioService.newURI(urlToAdd, null); + } + catch(e) { + // it isn't a valid url + // we'll leave uriToAdd as "undefined" and handle that later } - var uriToAdd = ioService.newURI(urlToAdd, null); while(elements.hasMoreElements()) { entry = elements.getNext(); - if (entry) { - index ++; - entry= entry.QueryInterface(Components.interfaces.nsIRDFLiteral); - var rdfValue = entry.Value; + if (!entry) continue; - try { - var unused = { }; - var scheme = ioService.extractScheme(rdfValue, unused, unused); - } catch(e) { - rdfValue = "http://" + rdfValue; + index ++; + entry= entry.QueryInterface(Components.interfaces.nsIRDFLiteral); + var rdfValue = entry.Value; + + try { + var unused = { }; + var scheme = ioService.extractScheme(rdfValue, unused, unused); + } catch(e) { + rdfValue = "http://" + rdfValue; + } + + if (uriToAdd) { + try { + var rdfUri = ioService.newURI(rdfValue, null); + + if (rdfUri.equals(uriToAdd)) { + // URI already present in the database + // Remove it from its current position. + // It is inserted to the top after the while loop. + entries.RemoveElementAt(index, true); + break; + } } + + // the uri is still not recognized by the ioservice + catch(ex) { + // no problem, we'll handle this below + } + } - var rdfUri = ioService.newURI(rdfValue, null); - - if (rdfUri.equals(uriToAdd)) { - // URI already present in the database - // Remove it from its current position. - // It is inserted to the top after the while loop. - entries.RemoveElementAt(index, true); - break; - } + // if we got this far, then something is funky with the URIs, + // so we need to do a straight string compare of the raw strings + if (urlToAdd == rdfValue) { + entries.RemoveElementAt(index, true); + break; } } // while @@ -176,7 +199,7 @@ function addToUrlbarHistory() // this grow without bound. for (index = entries.GetCount(); index > MAX_HISTORY_ITEMS; --index) { entries.RemoveElementAt(index, true); - } // for + } // for } // localstore }