7d630742f6a1c185e80cf46abf5af0b704db1784 galt Fri May 17 23:41:18 2019 -0700 Adding check that A tags are NOT nested. For htmlCheck. diff --git src/lib/htmlPage.c src/lib/htmlPage.c index 33fb36e..218289b 100644 --- src/lib/htmlPage.c +++ src/lib/htmlPage.c @@ -1946,41 +1946,57 @@ touppers(tag->name); /* Add singleton tags to hash. */ struct hash *singleTonHash = hashNew(8); int i; int count=ArraySize(singleTons); for (i=0; i<count; ++i) hashAdd(singleTonHash, singleTons[i], NULL); /* Add selfCloser tags to hash. */ struct hash *selfCloserHash = hashNew(8); count=ArraySize(selfClosers); for (i=0; i<count; ++i) hashAdd(selfCloserHash, selfClosers[i], NULL); +boolean inA = FALSE; // inside A tag. (A tags may not be nested.) struct slName *tagStack = NULL; for (tag = page->tags; tag != NULL; tag = tag->next) { if (isEmpty(tag->name)) // causes a blank tag tagAbort(page, tag, "Space not allowed between opening bracket < and tag name"); + if (sameString(tag->name,"A")) // A open tag + { + if (inA) + tagAbort(page, tag, "A tags may not be nested inside one another."); + else + inA = TRUE; + } + if (startsWith("/", tag->name)) { if (sameString(tag->name,"/")) // causes a blank close tag tagAbort(page, tag, "Space not allowed between opening bracket </ and closing tag name"); if (tag->attributes) tagAbort(page, tag, "Attributes are not allowed in closing tag: [%s]", tag->name); + if (sameString(tag->name,"/A")) // A close tag + { + if (inA) + inA = FALSE; + else + tagAbort(page, tag, "/A close tag with no open tag."); + } if (hashLookup(singleTonHash, tag->name+1)) tagAbort(page, tag, "Tag %s closing tag not allowed for singleton tags.", tag->name); if (!sameString("P", tag->name+1)) { if (!tagStack) tagAbort(page, tag, "No tags still left on stack. Closing tag %s has no corresponding open tag.", tag->name); struct slName *top = slPopHead(&tagStack); // flush LI tags still on stack when /UL or /OL encountered // since the missing /LI tags are usually tolerated. while ((sameString(tag->name, "/UL") || sameString(tag->name, "/OL")) && sameString(top->name,"LI")) { tagWarn(page, tag, "Closing tag %s found. LI tag on stack. Missing /LI tag. Please fix. Continuing.", tag->name); top = slPopHead(&tagStack); } if (!sameString(top->name,tag->name+1))