diff --git a/web.d b/web.d index 00ec20e..c0a70e1 100644 --- a/web.d +++ b/web.d @@ -268,6 +268,8 @@ class ApiProvider : WebDotDBaseType { /// Adds CSRF tokens to the document for use by script (required by the Javascript API) /// and then calls addCsrfTokens(document.root) to add them to all POST forms as well. protected void addCsrfTokens(Document document) { + if(document is null) + return; if(!csrfTokenAddedToScript) { auto tokenInfo = _getCsrfInfo(); if(tokenInfo is null) @@ -291,24 +293,28 @@ class ApiProvider : WebDotDBaseType { } private bool csrfTokenAddedToScript; - private bool csrfTokenAddedToForms; + //private bool csrfTokenAddedToForms; /// This adds CSRF tokens to all forms in the tree protected void addCsrfTokens(Element element) { - if(!csrfTokenAddedToForms) { + if(element is null) + return; + //if(!csrfTokenAddedToForms) { auto tokenInfo = _getCsrfInfo(); if(tokenInfo is null) return; - foreach(formElement; element.querySelectorAll("form[method=POST]")) { + foreach(formElement; element.getElementsByTagName("form")) { + if(formElement.method != "POST" && formElement.method != "post") + continue; auto form = cast(Form) formElement; assert(form !is null); form.setValue(tokenInfo["key"], tokenInfo["token"]); } - csrfTokenAddedToForms = true; - } + //csrfTokenAddedToForms = true; + //} } // and added to ajax forms.. @@ -404,7 +410,7 @@ class ApiProvider : WebDotDBaseType { assert(ret !is null); } body { - auto document = new Document("