diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 614641057b6..b05d6e6e74c 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -99,6 +99,7 @@ #include "nsIMultiPartChannel.h" #include "nsIRefreshURI.h" #include "nsIWebNavigation.h" +#include "nsIConsoleService.h" #include "nsNetUtil.h" // for NS_MakeAbsoluteURI @@ -2301,6 +2302,22 @@ nsDocument::BeginLoad() NS_DOCUMENT_NOTIFY_OBSERVERS(BeginLoad, (this)); } +PRBool +nsDocument::CheckGetElementByIdArg(const nsAString& aId) +{ + if (aId.IsEmpty()) { + nsCOMPtr consoleService + (do_GetService("@mozilla.org/consoleservice;1")); + + if (consoleService) { + consoleService->LogStringMessage(NS_LITERAL_STRING( + "Empty string passed to getElementById().").get()); + } + return PR_FALSE; + } + return PR_TRUE; +} + static void GetDocumentFromDocShellTreeItem(nsIDocShellTreeItem *aDocShell, nsIDocument **aDocument) diff --git a/mozilla/content/base/src/nsDocument.h b/mozilla/content/base/src/nsDocument.h index 7a5da61d2f7..635885766c7 100644 --- a/mozilla/content/base/src/nsDocument.h +++ b/mozilla/content/base/src/nsDocument.h @@ -643,6 +643,13 @@ public: protected: + /** + * Check that aId is not empty and log a message to the console + * service if it is. + * @returns PR_TRUE if aId looks correct, PR_FALSE otherwise. + */ + static PRBool CheckGetElementByIdArg(const nsAString& aId); + void DispatchContentLoadedEvents(); void RetrieveRelevantHeaders(nsIChannel *aChannel); diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index b117b6c2d03..8fae66bb332 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -2475,10 +2475,7 @@ nsHTMLDocument::GetElementById(const nsAString& aElementId, return GetElementById(aElementId, aReturn); } - NS_ASSERTION(!aElementId.IsEmpty(), - "getElementById(\"\") called, fix caller?"); - - if (mRootContent && !aElementId.IsEmpty()) { + if (mRootContent && CheckGetElementByIdArg(aElementId)) { e = nsContentUtils::MatchElementId(mRootContent, idAtom); } } diff --git a/mozilla/content/xml/document/src/nsXMLDocument.cpp b/mozilla/content/xml/document/src/nsXMLDocument.cpp index b3ef892d03c..e92acbb2ccb 100644 --- a/mozilla/content/xml/document/src/nsXMLDocument.cpp +++ b/mozilla/content/xml/document/src/nsXMLDocument.cpp @@ -673,8 +673,7 @@ nsXMLDocument::GetElementById(const nsAString& aElementId, NS_ENSURE_ARG_POINTER(aReturn); *aReturn = nsnull; - NS_ASSERTION(!aElementId.IsEmpty(), "getElementById(\"\"), fix caller?"); - if (aElementId.IsEmpty()) + if (!CheckGetElementByIdArg(aElementId)) return NS_OK; // If we tried to load a document and something went wrong, we might not have diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index ba874080611..b13ed39bebd 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -1616,9 +1616,8 @@ nsXULDocument::GetElementById(const nsAString& aId, NS_ENSURE_ARG_POINTER(aReturn); *aReturn = nsnull; - NS_ASSERTION(!aId.IsEmpty(),"getElementById(\"\"), fix caller?"); - if (aId.IsEmpty()) - return NS_OK; + if (!CheckGetElementByIdArg(aId)) + return NS_OK; nsresult rv;