From 495164e9389936f3d58bc4647657fcf78fceca2e Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Wed, 27 Jun 2007 14:30:45 +0000 Subject: [PATCH] Release 2.0.1, merged in 1181 to HEAD. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/branches/strict@1255 48356398-32a2-884e-a903-53898d9a118a --- Doxyfile | 2 +- INSTALL | 53 ++++- NEWS | 44 ++++ TODO | 38 +--- VERSION | 2 +- WHATSNEW | 19 +- art/100cases.png | Bin 0 -> 2732 bytes benchmarks/Lexer.php | 2 +- benchmarks/ProfileDirectLex.php | 2 - configdoc/generate.php | 5 +- configdoc/library/ConfigDoc.auto.php | 1 - configdoc/library/ConfigDoc.php | 1 - configdoc/library/ConfigDoc/HTMLXSLTProcessor.php | 2 +- configdoc/library/ConfigDoc/XMLSerializer.php | 1 - .../ConfigDoc/XMLSerializer/ConfigSchema.php | 7 +- .../library/ConfigDoc/XMLSerializer/Types.php | 1 - configdoc/styles/plain.xsl | 22 +- docs/dev-advanced-api.html | 2 +- docs/dev-naming.html | 2 +- docs/dev-optimization.html | 2 +- docs/dev-progress.html | 2 +- docs/enduser-customize.html | 7 +- docs/enduser-id.html | 2 +- docs/enduser-slow.html | 2 +- docs/enduser-tidy.html | 7 +- docs/enduser-utf8.html | 2 +- docs/enduser-youtube.html | 2 +- docs/examples/basic.php | 1 - docs/index.html | 2 +- docs/ref-devnetwork.html | 2 +- docs/ref-proprietary-tags.txt | 2 +- library/HTMLPurifier.auto.php | 1 - library/HTMLPurifier.func.php | 1 - library/HTMLPurifier.php | 24 +- library/HTMLPurifier/AttrCollections.php | 1 - library/HTMLPurifier/AttrDef.php | 1 - library/HTMLPurifier/AttrDef/CSS.php | 1 - library/HTMLPurifier/AttrDef/CSS/Background.php | 1 - .../AttrDef/CSS/BackgroundPosition.php | 1 - library/HTMLPurifier/AttrDef/CSS/Border.php | 1 - library/HTMLPurifier/AttrDef/CSS/Color.php | 1 - library/HTMLPurifier/AttrDef/CSS/Composite.php | 1 - library/HTMLPurifier/AttrDef/CSS/Font.php | 1 - library/HTMLPurifier/AttrDef/CSS/FontFamily.php | 1 - library/HTMLPurifier/AttrDef/CSS/Length.php | 1 - library/HTMLPurifier/AttrDef/CSS/ListStyle.php | 1 - library/HTMLPurifier/AttrDef/CSS/Multiple.php | 1 - library/HTMLPurifier/AttrDef/CSS/Number.php | 1 - library/HTMLPurifier/AttrDef/CSS/Percentage.php | 1 - .../HTMLPurifier/AttrDef/CSS/TextDecoration.php | 1 - library/HTMLPurifier/AttrDef/CSS/URI.php | 1 - library/HTMLPurifier/AttrDef/Enum.php | 1 - library/HTMLPurifier/AttrDef/HTML/Bool.php | 1 - library/HTMLPurifier/AttrDef/HTML/Color.php | 1 - library/HTMLPurifier/AttrDef/HTML/FrameTarget.php | 1 - library/HTMLPurifier/AttrDef/HTML/ID.php | 1 - library/HTMLPurifier/AttrDef/HTML/Length.php | 1 - library/HTMLPurifier/AttrDef/HTML/LinkTypes.php | 1 - library/HTMLPurifier/AttrDef/HTML/MultiLength.php | 1 - library/HTMLPurifier/AttrDef/HTML/Nmtokens.php | 1 - library/HTMLPurifier/AttrDef/HTML/Pixels.php | 1 - library/HTMLPurifier/AttrDef/Integer.php | 1 - library/HTMLPurifier/AttrDef/Lang.php | 1 - library/HTMLPurifier/AttrDef/Text.php | 1 - library/HTMLPurifier/AttrDef/URI.php | 2 +- library/HTMLPurifier/AttrDef/URI/Email.php | 1 - .../HTMLPurifier/AttrDef/URI/Email/SimpleCheck.php | 1 - library/HTMLPurifier/AttrDef/URI/Host.php | 1 - library/HTMLPurifier/AttrDef/URI/IPv4.php | 1 - library/HTMLPurifier/AttrDef/URI/IPv6.php | 1 - library/HTMLPurifier/AttrTransform.php | 1 - library/HTMLPurifier/AttrTransform/BdoDir.php | 1 - library/HTMLPurifier/AttrTransform/BgColor.php | 1 - library/HTMLPurifier/AttrTransform/BoolToCSS.php | 1 - library/HTMLPurifier/AttrTransform/Border.php | 1 - library/HTMLPurifier/AttrTransform/EnumToCSS.php | 1 - library/HTMLPurifier/AttrTransform/ImgRequired.php | 1 - library/HTMLPurifier/AttrTransform/ImgSpace.php | 1 - library/HTMLPurifier/AttrTransform/Lang.php | 1 - library/HTMLPurifier/AttrTransform/Length.php | 1 - library/HTMLPurifier/AttrTransform/Name.php | 1 - library/HTMLPurifier/AttrTypes.php | 2 +- library/HTMLPurifier/AttrValidator.php | 68 ++++-- library/HTMLPurifier/CSSDefinition.php | 1 - library/HTMLPurifier/ChildDef.php | 7 +- library/HTMLPurifier/ChildDef/Chameleon.php | 2 +- library/HTMLPurifier/ChildDef/Custom.php | 7 +- library/HTMLPurifier/ChildDef/Empty.php | 1 - library/HTMLPurifier/ChildDef/Optional.php | 1 - library/HTMLPurifier/ChildDef/Required.php | 3 +- library/HTMLPurifier/ChildDef/StrictBlockquote.php | 1 - library/HTMLPurifier/ChildDef/Table.php | 3 +- library/HTMLPurifier/Config.php | 86 +++++-- library/HTMLPurifier/ConfigDef.php | 1 - library/HTMLPurifier/ConfigDef/Directive.php | 7 +- library/HTMLPurifier/ConfigDef/DirectiveAlias.php | 1 - library/HTMLPurifier/ConfigDef/Namespace.php | 1 - library/HTMLPurifier/ConfigSchema.php | 5 +- library/HTMLPurifier/ContentSets.php | 1 - library/HTMLPurifier/Context.php | 16 +- library/HTMLPurifier/Definition.php | 1 - library/HTMLPurifier/DefinitionCache.php | 21 +- library/HTMLPurifier/DefinitionCache/Decorator.php | 4 - .../DefinitionCache/Decorator/Cleanup.php | 1 - .../DefinitionCache/Decorator/Memory.php | 1 - .../DefinitionCache/Decorator/Template.php.in | 1 - library/HTMLPurifier/DefinitionCache/Null.php | 1 - .../HTMLPurifier/DefinitionCache/Serializer.php | 73 +++++- library/HTMLPurifier/DefinitionCacheFactory.php | 12 +- library/HTMLPurifier/Doctype.php | 21 +- library/HTMLPurifier/DoctypeRegistry.php | 13 +- library/HTMLPurifier/ElementDef.php | 12 +- library/HTMLPurifier/Encoder.php | 1 - library/HTMLPurifier/EntityLookup.php | 1 - library/HTMLPurifier/EntityParser.php | 1 - library/HTMLPurifier/Error.php | 1 - library/HTMLPurifier/ErrorCollector.php | 97 +++++--- library/HTMLPurifier/Filter.php | 1 - library/HTMLPurifier/Filter/YouTube.php | 1 - library/HTMLPurifier/Generator.php | 39 +++- library/HTMLPurifier/HTMLDefinition.php | 6 +- library/HTMLPurifier/HTMLModule.php | 1 - library/HTMLPurifier/HTMLModule/Bdo.php | 1 - .../HTMLPurifier/HTMLModule/CommonAttributes.php | 1 - library/HTMLPurifier/HTMLModule/Edit.php | 1 - library/HTMLPurifier/HTMLModule/Hypertext.php | 1 - library/HTMLPurifier/HTMLModule/Image.php | 1 - library/HTMLPurifier/HTMLModule/Legacy.php | 1 - library/HTMLPurifier/HTMLModule/List.php | 4 +- .../HTMLModule/NonXMLCommonAttributes.php | 1 - library/HTMLPurifier/HTMLModule/Presentation.php | 1 - library/HTMLPurifier/HTMLModule/Scripting.php | 10 +- library/HTMLPurifier/HTMLModule/StyleAttribute.php | 1 - library/HTMLPurifier/HTMLModule/Tables.php | 6 +- library/HTMLPurifier/HTMLModule/Target.php | 1 - library/HTMLPurifier/HTMLModule/Text.php | 9 +- library/HTMLPurifier/HTMLModule/Tidy.php | 2 +- .../HTMLPurifier/HTMLModule/Tidy/Proprietary.php | 1 - library/HTMLPurifier/HTMLModule/Tidy/XHTML.php | 1 - .../HTMLPurifier/HTMLModule/Tidy/XHTMLAndHTML4.php | 1 - .../HTMLPurifier/HTMLModule/Tidy/XHTMLStrict.php | 1 - .../HTMLModule/XMLCommonAttributes.php | 1 - library/HTMLPurifier/HTMLModuleManager.php | 50 +++- library/HTMLPurifier/IDAccumulator.php | 1 - library/HTMLPurifier/Injector.php | 85 +++++++ library/HTMLPurifier/Injector/AutoParagraph.php | 244 ++++++++++++++++++++ library/HTMLPurifier/Injector/Linkify.php | 52 +++++ library/HTMLPurifier/Injector/PurifierLinkify.php | 62 +++++ library/HTMLPurifier/Language.php | 95 +++++++- .../HTMLPurifier/Language/classes/en-x-test.php | 1 - .../HTMLPurifier/Language/messages/en-x-test.php | 3 +- library/HTMLPurifier/Language/messages/en.php | 71 ++++-- library/HTMLPurifier/LanguageFactory.php | 26 ++- library/HTMLPurifier/Lexer.php | 36 ++- library/HTMLPurifier/Lexer/DOMLex.php | 20 +- library/HTMLPurifier/Lexer/DirectLex.php | 94 ++++++-- library/HTMLPurifier/Lexer/PEARSax3.php | 1 - library/HTMLPurifier/PercentEncoder.php | 1 - library/HTMLPurifier/Printer.php | 11 +- library/HTMLPurifier/Printer/CSSDefinition.php | 1 - library/HTMLPurifier/Printer/ConfigForm.php | 58 +++-- library/HTMLPurifier/Printer/HTMLDefinition.php | 89 ++++++-- library/HTMLPurifier/Strategy.php | 1 - library/HTMLPurifier/Strategy/Composite.php | 1 - library/HTMLPurifier/Strategy/Core.php | 1 - library/HTMLPurifier/Strategy/FixNesting.php | 31 ++- library/HTMLPurifier/Strategy/MakeWellFormed.php | 251 +++++++++++++++----- .../Strategy/RemoveForeignElements.php | 60 ++++- .../HTMLPurifier/Strategy/ValidateAttributes.php | 9 +- library/HTMLPurifier/TagTransform.php | 1 - library/HTMLPurifier/TagTransform/Font.php | 4 +- library/HTMLPurifier/TagTransform/Simple.php | 1 - library/HTMLPurifier/Token.php | 30 +-- library/HTMLPurifier/TokenFactory.php | 1 - library/HTMLPurifier/URIScheme.php | 1 - library/HTMLPurifier/URIScheme/ftp.php | 1 - library/HTMLPurifier/URIScheme/http.php | 1 - library/HTMLPurifier/URIScheme/https.php | 1 - library/HTMLPurifier/URIScheme/mailto.php | 1 - library/HTMLPurifier/URIScheme/news.php | 1 - library/HTMLPurifier/URIScheme/nntp.php | 1 - library/HTMLPurifier/URISchemeRegistry.php | 2 +- maintenance/flush-htmldefinition-cache.php | 1 - maintenance/generate-entity-file.php | 1 - package.php | 1 - release1-update.php | 1 - release2-strict.php | 1 - release3-tag.php | 1 - smoketests/all.php | 2 +- smoketests/attrTransform.php | 2 +- smoketests/attrTransform.xml | 2 +- smoketests/basic.php | 2 +- smoketests/basic/allElements.css | 2 +- smoketests/basic/allElements.html | 2 +- smoketests/basic/legacy.html | 2 +- smoketests/common.php | 1 - smoketests/configForm.php | 4 +- smoketests/loadFunc.php | 2 +- smoketests/preserveYouTube.php | 2 +- smoketests/printDefinition.php | 17 +- smoketests/testSchema.php | 83 ++++--- smoketests/utf8.php | 2 +- smoketests/variableWidthAttack.php | 2 +- smoketests/xssAttacks.php | 2 +- svn.php | 1 - test-settings.sample.php | 1 - tests/Debugger.php | 14 +- tests/HTMLPurifier/AttrCollectionsTest.php | 7 +- .../AttrDef/CSS/BackgroundPositionTest.php | 1 - tests/HTMLPurifier/AttrDef/CSS/BackgroundTest.php | 1 - tests/HTMLPurifier/AttrDef/CSS/BorderTest.php | 1 - tests/HTMLPurifier/AttrDef/CSS/ColorTest.php | 1 - tests/HTMLPurifier/AttrDef/CSS/CompositeTest.php | 13 +- tests/HTMLPurifier/AttrDef/CSS/FontFamilyTest.php | 1 - tests/HTMLPurifier/AttrDef/CSS/FontTest.php | 1 - tests/HTMLPurifier/AttrDef/CSS/LengthTest.php | 1 - tests/HTMLPurifier/AttrDef/CSS/ListStyleTest.php | 1 - tests/HTMLPurifier/AttrDef/CSS/MultipleTest.php | 1 - tests/HTMLPurifier/AttrDef/CSS/NumberTest.php | 1 - tests/HTMLPurifier/AttrDef/CSS/PercentageTest.php | 1 - .../AttrDef/CSS/TextDecorationTest.php | 1 - tests/HTMLPurifier/AttrDef/CSS/URITest.php | 1 - tests/HTMLPurifier/AttrDef/CSSTest.php | 1 - tests/HTMLPurifier/AttrDef/EnumTest.php | 1 - tests/HTMLPurifier/AttrDef/HTML/BoolTest.php | 1 - tests/HTMLPurifier/AttrDef/HTML/ColorTest.php | 1 - .../HTMLPurifier/AttrDef/HTML/FrameTargetTest.php | 1 - tests/HTMLPurifier/AttrDef/HTML/IDTest.php | 1 - tests/HTMLPurifier/AttrDef/HTML/LengthTest.php | 1 - tests/HTMLPurifier/AttrDef/HTML/LinkTypesTest.php | 1 - .../HTMLPurifier/AttrDef/HTML/MultiLengthTest.php | 1 - tests/HTMLPurifier/AttrDef/HTML/NmtokensTest.php | 1 - tests/HTMLPurifier/AttrDef/HTML/PixelsTest.php | 1 - tests/HTMLPurifier/AttrDef/IntegerTest.php | 1 - tests/HTMLPurifier/AttrDef/LangTest.php | 1 - tests/HTMLPurifier/AttrDef/TextTest.php | 1 - .../AttrDef/URI/Email/SimpleCheckTest.php | 1 - tests/HTMLPurifier/AttrDef/URI/EmailHarness.php | 1 - tests/HTMLPurifier/AttrDef/URI/HostTest.php | 1 - tests/HTMLPurifier/AttrDef/URI/IPv6Test.php | 1 - tests/HTMLPurifier/AttrDef/URITest.php | 6 +- tests/HTMLPurifier/AttrDefHarness.php | 1 - tests/HTMLPurifier/AttrDefTest.php | 1 - tests/HTMLPurifier/AttrTransform/BdoDirTest.php | 1 - tests/HTMLPurifier/AttrTransform/BgColorTest.php | 1 - tests/HTMLPurifier/AttrTransform/BoolToCSSTest.php | 1 - tests/HTMLPurifier/AttrTransform/BorderTest.php | 1 - tests/HTMLPurifier/AttrTransform/EnumToCSSTest.php | 1 - .../HTMLPurifier/AttrTransform/ImgRequiredTest.php | 1 - tests/HTMLPurifier/AttrTransform/ImgSpaceTest.php | 1 - tests/HTMLPurifier/AttrTransform/LangTest.php | 1 - tests/HTMLPurifier/AttrTransform/LengthTest.php | 1 - tests/HTMLPurifier/AttrTransform/NameTest.php | 1 - tests/HTMLPurifier/AttrTransformHarness.php | 1 - tests/HTMLPurifier/AttrTransformTest.php | 1 - tests/HTMLPurifier/AttrTypesTest.php | 1 - tests/HTMLPurifier/AttrValidator_ErrorsTest.php | 49 ++++ tests/HTMLPurifier/ChildDef/ChameleonTest.php | 1 - tests/HTMLPurifier/ChildDef/CustomTest.php | 11 +- tests/HTMLPurifier/ChildDef/OptionalTest.php | 1 - tests/HTMLPurifier/ChildDef/RequiredTest.php | 1 - .../HTMLPurifier/ChildDef/StrictBlockquoteTest.php | 8 +- tests/HTMLPurifier/ChildDef/TableTest.php | 6 +- tests/HTMLPurifier/ChildDefHarness.php | 2 +- tests/HTMLPurifier/ConfigSchemaTest.php | 1 - tests/HTMLPurifier/ConfigTest.php | 88 ++++++- tests/HTMLPurifier/ContextTest.php | 9 +- .../DefinitionCache/Decorator/CleanupTest.php | 1 - .../DefinitionCache/Decorator/MemoryTest.php | 1 - .../DefinitionCache/DecoratorHarness.php | 3 +- .../HTMLPurifier/DefinitionCache/DecoratorTest.php | 3 +- .../DefinitionCache/SerializerTest.php | 33 ++- tests/HTMLPurifier/DefinitionCacheFactoryTest.php | 1 - tests/HTMLPurifier/DefinitionCacheHarness.php | 3 +- tests/HTMLPurifier/DefinitionCacheTest.php | 23 +- tests/HTMLPurifier/DefinitionTest.php | 1 - tests/HTMLPurifier/DoctypeRegistryTest.php | 1 - tests/HTMLPurifier/ElementDefTest.php | 13 -- tests/HTMLPurifier/EncoderTest.php | 1 - tests/HTMLPurifier/EntityLookupTest.php | 1 - tests/HTMLPurifier/EntityParserTest.php | 1 - tests/HTMLPurifier/ErrorCollectorEMock.php | 46 ++++ tests/HTMLPurifier/ErrorCollectorTest.php | 183 +++++++++++---- tests/HTMLPurifier/ErrorsHarness.php | 31 +++ tests/HTMLPurifier/GeneratorTest.php | 26 ++- tests/HTMLPurifier/HTMLDefinitionTest.php | 1 - tests/HTMLPurifier/HTMLModule/ScriptingTest.php | 16 +- tests/HTMLPurifier/HTMLModule/TidyTest.php | 3 +- tests/HTMLPurifier/HTMLModuleHarness.php | 1 - tests/HTMLPurifier/HTMLModuleManagerTest.php | 7 +- tests/HTMLPurifier/HTMLModuleTest.php | 1 - tests/HTMLPurifier/Harness.php | 15 +- tests/HTMLPurifier/IDAccumulatorTest.php | 1 - tests/HTMLPurifier/Injector/AutoParagraphTest.php | 253 +++++++++++++++++++++ tests/HTMLPurifier/Injector/LinkifyTest.php | 38 ++++ .../HTMLPurifier/Injector/PurifierLinkifyTest.php | 42 ++++ tests/HTMLPurifier/InjectorHarness.php | 15 ++ tests/HTMLPurifier/LanguageFactoryTest.php | 14 +- tests/HTMLPurifier/LanguageTest.php | 104 ++++++--- tests/HTMLPurifier/Lexer/DirectLexTest.php | 25 +- tests/HTMLPurifier/Lexer/DirectLex_ErrorsTest.php | 55 +++++ tests/HTMLPurifier/LexerTest.php | 30 ++- tests/HTMLPurifier/PercentEncoderTest.php | 1 - tests/HTMLPurifier/SimpleTest/Reporter.php | 1 - tests/HTMLPurifier/Strategy/CompositeTest.php | 7 +- tests/HTMLPurifier/Strategy/CoreTest.php | 5 +- tests/HTMLPurifier/Strategy/ErrorsHarness.php | 19 ++ tests/HTMLPurifier/Strategy/FixNestingTest.php | 6 +- .../Strategy/FixNesting_ErrorsTest.php | 38 ++++ tests/HTMLPurifier/Strategy/MakeWellFormedTest.php | 45 +++- .../Strategy/MakeWellFormed_ErrorsTest.php | 56 +++++ .../Strategy/RemoveForeignElementsTest.php | 13 +- .../Strategy/RemoveForeignElements_ErrorsTest.php | 59 +++++ .../Strategy/ValidateAttributesTest.php | 2 +- tests/HTMLPurifier/StrategyHarness.php | 1 - tests/HTMLPurifier/TagTransformTest.php | 1 - tests/HTMLPurifier/TokenFactoryTest.php | 1 - tests/HTMLPurifier/TokenTest.php | 1 - tests/HTMLPurifier/URISchemeRegistryTest.php | 7 +- tests/HTMLPurifier/URISchemeTest.php | 1 - tests/HTMLPurifierTest.php | 40 +++- tests/generate_mock_once.func.php | 1 - tests/index.php | 2 +- tests/path2class.func.php | 1 - tests/tally_errors.func.php | 1 - tests/test_files.php | 9 +- 326 files changed, 3097 insertions(+), 898 deletions(-) rewrite WHATSNEW (100%) create mode 100644 art/100cases.png create mode 100644 library/HTMLPurifier/Injector.php create mode 100644 library/HTMLPurifier/Injector/AutoParagraph.php create mode 100644 library/HTMLPurifier/Injector/Linkify.php create mode 100644 library/HTMLPurifier/Injector/PurifierLinkify.php rewrite library/HTMLPurifier/Language/messages/en.php (61%) rewrite smoketests/testSchema.php (70%) create mode 100644 tests/HTMLPurifier/AttrValidator_ErrorsTest.php create mode 100644 tests/HTMLPurifier/ErrorCollectorEMock.php rewrite tests/HTMLPurifier/ErrorCollectorTest.php (65%) create mode 100644 tests/HTMLPurifier/ErrorsHarness.php create mode 100644 tests/HTMLPurifier/Injector/AutoParagraphTest.php create mode 100644 tests/HTMLPurifier/Injector/LinkifyTest.php create mode 100644 tests/HTMLPurifier/Injector/PurifierLinkifyTest.php create mode 100644 tests/HTMLPurifier/InjectorHarness.php rewrite tests/HTMLPurifier/LanguageTest.php (61%) create mode 100644 tests/HTMLPurifier/Lexer/DirectLex_ErrorsTest.php create mode 100644 tests/HTMLPurifier/Strategy/ErrorsHarness.php create mode 100644 tests/HTMLPurifier/Strategy/FixNesting_ErrorsTest.php create mode 100644 tests/HTMLPurifier/Strategy/MakeWellFormed_ErrorsTest.php create mode 100644 tests/HTMLPurifier/Strategy/RemoveForeignElements_ErrorsTest.php diff --git a/Doxyfile b/Doxyfile index c96f6773..8ecf65ae 100644 --- a/Doxyfile +++ b/Doxyfile @@ -4,7 +4,7 @@ # Project related configuration options #--------------------------------------------------------------------------- PROJECT_NAME = HTML Purifier -PROJECT_NUMBER = 2.0.0 +PROJECT_NUMBER = 2.0.1 OUTPUT_DIRECTORY = "C:/Documents and Settings/Edward/My Documents/My Webs/htmlpurifier/docs/doxygen" CREATE_SUBDIRS = NO OUTPUT_LANGUAGE = English diff --git a/INSTALL b/INSTALL index f8f137aa..1d68c0c9 100644 --- a/INSTALL +++ b/INSTALL @@ -49,7 +49,7 @@ be standards compliant. HTML Purifier can deal with these doctypes: * XHTML 1.0 Strict * HTML 4.01 Transitional * HTML 4.01 Strict -* XHTML 1.1 sans Ruby +* XHTML 1.1 (sans Ruby) ...and these character encodings: @@ -117,8 +117,9 @@ websites): Note that HTML Purifier's support for non-Unicode encodings is crippled by the fact that any character not supported by that encoding will be silently dropped, EVEN if it is ampersand escaped. If you want to work around -this, you are welcome to read docs/enduser-utf8.html for a workaround, -but please be cognizant of the issues the "solution" creates. +this, you are welcome to read docs/enduser-utf8.html for a fix, +but please be cognizant of the issues the "solution" creates (for this +reason, I do not include the solution in this document). @@ -148,7 +149,9 @@ Other supported doctypes include: There are more configuration directives which can be read about here: They're a bit boring, but they can help out for those of you who like to exert maximum control over -your code. +your code. Some of the more interesting ones are configurable at the +demo and are well worth looking into +for your own system. @@ -165,13 +168,15 @@ The interface is mind-numbingly simple: $clean_html = $purifier->purify( $dirty_html ); That's it! For more examples, check out docs/examples/ (they aren't very -different though). Also, SLOW gives advice on what to do if HTML Purifier -is slowing down your application. +different though). Also, docs/enduser-slow.html gives advice on what to +do if HTML Purifier is slowing down your application. 6. Quick install +First, make sure library/HTMLPurifier/DefinitionCache/Serializer is +writable by the webserver (see Section 7: Caching below for details). If your website is in UTF-8 and XHTML Transitional, use this code: set('Core', 'DefinitionCache', null); + +Or move the cache directory somewhere else (no trailing slash): + + $config->set('Cache', 'SerializerPath', '/home/user/absolute/path'); diff --git a/NEWS b/NEWS index b13db9b2..19b70259 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,50 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier . Internal change ========================== +2.0.1, released 2007-06-27 +! Tag auto-closing now based on a ChildDef heuristic rather than a + manually set auto_close array; some behavior may change +! Experimental AutoFormat functionality added: auto-paragraph and + linkify your HTML input by setting %AutoFormat.AutoParagraph and + %AutoFormat.Linkify to true +! Newlines normalized internally, and then converted back to the + value of PHP_EOL. If this is not desired, set your newline format + using %Output.Newline. +! Beta error collection, messages are implemented for the most generic + cases involving Lexing or Strategies +- Clean up special case code for )#si', + array('HTMLPurifier_Lexer_DirectLex', 'scriptCallback'), $html); + } + $html = $this->normalize($html, $config, $context); $cursor = 0; // our location in the text @@ -47,12 +61,26 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer $array = array(); // result array $maintain_line_numbers = $config->get('Core', 'MaintainLineNumbers'); - $current_line = 1; - $nl = PHP_EOL; + + if ($maintain_line_numbers === null) { + // automatically determine line numbering by checking + // if error collection is on + $maintain_line_numbers = $config->get('Core', 'CollectErrors'); + } + + if ($maintain_line_numbers) $current_line = 1; + else $current_line = false; + $context->register('CurrentLine', $current_line); + $nl = "\n"; // how often to manually recalculate. This will ALWAYS be right, // but it's pretty wasteful. Set to 0 to turn off $synchronize_interval = $config->get('Core', 'DirectLexLineNumberSyncInterval'); + $e = false; + if ($config->get('Core', 'CollectErrors')) { + $e =& $context->get('ErrorCollector'); + } + // infinite loop protection // has to be pretty big, since html docs can be big // we're allow two hundred thousand tags... more than enough? @@ -126,22 +154,35 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer // Check if it's a comment if ( - substr($segment, 0, 3) == '!--' && - substr($segment, $strlen_segment-2, 2) == '--' + substr($segment, 0, 3) == '!--' ) { + // re-determine segment length, looking for --> + $position_comment_end = strpos($html, '-->', $cursor); + if ($position_comment_end === false) { + // uh oh, we have a comment that extends to + // infinity. Can't be helped: set comment + // end position to end of string + if ($e) $e->send(E_WARNING, 'Lexer: Unclosed comment'); + $position_comment_end = strlen($html); + $end = true; + } else { + $end = false; + } + $strlen_segment = $position_comment_end - $cursor; + $segment = substr($html, $cursor, $strlen_segment); $token = new HTMLPurifier_Token_Comment( substr( - $segment, 3, $strlen_segment - 5 + $segment, 3, $strlen_segment - 3 ) ); if ($maintain_line_numbers) { $token->line = $current_line; - $current_line += $this->substrCount($html, $nl, $cursor, $position_next_gt - $cursor); + $current_line += $this->substrCount($html, $nl, $cursor, $strlen_segment); } $array[] = $token; + $cursor = $end ? $position_comment_end : $position_comment_end + 3; $inside_tag = false; - $cursor = $position_next_gt + 1; continue; } @@ -164,6 +205,7 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer // have accidently grabbed an emoticon. Translate into // text and go our merry way if (!ctype_alnum($segment[0])) { + if ($e) $e->send(E_NOTICE, 'Lexer: Unescaped lt'); $token = new HTMLPurifier_Token_Text( '<' . @@ -242,6 +284,8 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer $inside_tag = false; continue; } else { + // inside tag, but there's no ending > sign + if ($e) $e->send(E_WARNING, 'Lexer: Missing gt'); $token = new HTMLPurifier_Token_Text( '<' . @@ -256,6 +300,8 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer } break; } + + $context->destroy('CurrentLine'); return $array; } @@ -286,6 +332,11 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer if ($string == '') return array(); // no attributes + $e = false; + if ($config->get('Core', 'CollectErrors')) { + $e =& $context->get('ErrorCollector'); + } + // let's see if we can abort as quickly as possible // one equal sign, no spaces => one attribute $num_equal = substr_count($string, '='); @@ -297,7 +348,10 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer // only one attribute list($key, $quoted_value) = explode('=', $string); $quoted_value = trim($quoted_value); - if (!$key) return array(); + if (!$key) { + if ($e) $e->send(E_ERROR, 'Lexer: Missing attribute key'); + return array(); + } if (!$quoted_value) return array($key => ''); $first_char = @$quoted_value[0]; $last_char = @$quoted_value[strlen($quoted_value)-1]; @@ -311,6 +365,7 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer } else { // not well behaved if ($open_quote) { + if ($e) $e->send(E_ERROR, 'Lexer: Missing end quote'); $value = substr($quoted_value, 1); } else { $value = $quoted_value; @@ -334,7 +389,10 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer while(true) { // infinite loop protection - if (++$loops > 1000) return array(); + if (++$loops > 1000) { + trigger_error('Infinite loop detected in attribute parsing', E_USER_WARNING); + return array(); + } if ($cursor >= $size) { break; @@ -353,7 +411,11 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer $key = substr($string, $key_begin, $key_end - $key_begin); - if (!$key) continue; // empty key + if (!$key) { + if ($e) $e->send(E_ERROR, 'Lexer: Missing attribute key'); + $cursor += strcspn($string, $this->_whitespace, $cursor + 1); // prevent infinite loop + continue; // empty key + } // scroll past all whitespace $cursor += strspn($string, $this->_whitespace, $cursor); @@ -398,6 +460,9 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer // boolattr if ($key !== '') { $array[$key] = $key; + } else { + // purely theoretical + if ($e) $e->send(E_ERROR, 'Lexer: Missing attribute key'); } } @@ -407,4 +472,3 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/Lexer/PEARSax3.php b/library/HTMLPurifier/Lexer/PEARSax3.php index 18777ef7..3888229b 100644 --- a/library/HTMLPurifier/Lexer/PEARSax3.php +++ b/library/HTMLPurifier/Lexer/PEARSax3.php @@ -107,4 +107,3 @@ class HTMLPurifier_Lexer_PEARSax3 extends HTMLPurifier_Lexer } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/PercentEncoder.php b/library/HTMLPurifier/PercentEncoder.php index 7a12caaa..e32421e1 100644 --- a/library/HTMLPurifier/PercentEncoder.php +++ b/library/HTMLPurifier/PercentEncoder.php @@ -44,4 +44,3 @@ class HTMLPurifier_PercentEncoder } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/Printer.php b/library/HTMLPurifier/Printer.php index 95be17a2..7e20daaf 100644 --- a/library/HTMLPurifier/Printer.php +++ b/library/HTMLPurifier/Printer.php @@ -27,6 +27,16 @@ class HTMLPurifier_Printer } /** + * Give generator necessary configuration if possible + */ + function prepareGenerator($config) { + // hack for smoketests/configForm.php + if (empty($config->conf['HTML'])) return; + $context = new HTMLPurifier_Context(); + $this->generator->generateFromTokens(array(), $config, $context); + } + + /** * Main function that renders object or aspect of that object * @note Parameters vary depending on printer */ @@ -160,4 +170,3 @@ class HTMLPurifier_Printer } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/Printer/CSSDefinition.php b/library/HTMLPurifier/Printer/CSSDefinition.php index 7745f5f4..7d3ad61e 100644 --- a/library/HTMLPurifier/Printer/CSSDefinition.php +++ b/library/HTMLPurifier/Printer/CSSDefinition.php @@ -37,4 +37,3 @@ class HTMLPurifier_Printer_CSSDefinition extends HTMLPurifier_Printer } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/Printer/ConfigForm.php b/library/HTMLPurifier/Printer/ConfigForm.php index c157f2ab..fb86f5f3 100644 --- a/library/HTMLPurifier/Printer/ConfigForm.php +++ b/library/HTMLPurifier/Printer/ConfigForm.php @@ -38,18 +38,19 @@ class HTMLPurifier_Printer_ConfigForm extends HTMLPurifier_Printer /** * Returns HTML output for a configuration form * @param $config Configuration object of current form state - * @param $ns Optional namespace(s) to restrict form to + * @param $allowed Optional namespace(s) and directives to restrict form to. */ - function render($config, $ns = true) { + function render($config, $allowed = true, $render_controls = true) { $this->config = $config; - if ($ns === true) { - $all = $config->getAll(); - } else { - if (is_string($ns)) $ns = array($ns); - foreach ($ns as $n) { - $all = array($n => $config->getBatch($n)); - } + $this->prepareGenerator($config); + + $allowed = HTMLPurifier_Config::getAllowedDirectivesForForm($allowed); + $all = array(); + foreach ($allowed as $key) { + list($ns, $directive) = $key; + $all[$ns][$directive] = $config->get($ns, $directive); } + $ret = ''; $ret .= $this->start('table', array('class' => 'hp-config')); $ret .= $this->start('thead'); @@ -61,13 +62,16 @@ class HTMLPurifier_Printer_ConfigForm extends HTMLPurifier_Printer foreach ($all as $ns => $directives) { $ret .= $this->renderNamespace($ns, $directives); } - $ret .= $this->start('tfoot'); - $ret .= $this->start('tr'); - $ret .= $this->start('td', array('colspan' => 2, 'class' => 'controls')); - $ret .= ' [Reset]'; - $ret .= $this->end('td'); - $ret .= $this->end('tr'); - $ret .= $this->end('tfoot'); + if ($render_controls) { + $ret .= $this->start('tfoot'); + $ret .= $this->start('tr'); + $ret .= $this->start('td', array('colspan' => 2, 'class' => 'controls')); + $ret .= $this->elementEmpty('input', array('type' => 'Submit', 'value' => 'Submit')); + $ret .= '[Reset]'; + $ret .= $this->end('td'); + $ret .= $this->end('tr'); + $ret .= $this->end('tfoot'); + } $ret .= $this->end('table'); return $ret; } @@ -93,11 +97,20 @@ class HTMLPurifier_Printer_ConfigForm extends HTMLPurifier_Printer $url = str_replace('%s', urlencode("$ns.$directive"), $this->docURL); $ret .= $this->start('a', array('href' => $url)); } + $attr = array('for' => "{$this->name}:$ns.$directive"); + // crop directive name if it's too long + if (strlen($directive) < 14) { + $directive_disp = $directive; + } else { + $directive_disp = substr($directive, 0, 12) . '...'; + $attr['title'] = $directive; + } + $ret .= $this->element( 'label', - "%$ns.$directive", + $directive_disp, // component printers must create an element with this id - array('for' => "{$this->name}:$ns.$directive") + $attr ); if ($this->docURL) $ret .= $this->end('a'); $ret .= $this->end('th'); @@ -136,6 +149,7 @@ class HTMLPurifier_Printer_ConfigForm_NullDecorator extends HTMLPurifier_Printer $this->obj = $obj; } function render($ns, $directive, $value, $name, $config) { + $this->prepareGenerator($config); $ret = ''; $ret .= $this->start('label', array('for' => "$name:Null_$ns.$directive")); $ret .= $this->element('span', "$ns.$directive:", array('class' => 'verbose')); @@ -145,7 +159,7 @@ class HTMLPurifier_Printer_ConfigForm_NullDecorator extends HTMLPurifier_Printer 'type' => 'checkbox', 'value' => '1', 'class' => 'null-toggle', - 'name' => "$name:Null_$ns.$directive", + 'name' => "$name"."[Null_$ns.$directive]", 'id' => "$name:Null_$ns.$directive", 'onclick' => "toggleWriteability('$name:$ns.$directive',checked)" // INLINE JAVASCRIPT!!!! ); @@ -163,6 +177,7 @@ class HTMLPurifier_Printer_ConfigForm_NullDecorator extends HTMLPurifier_Printer */ class HTMLPurifier_Printer_ConfigForm_default extends HTMLPurifier_Printer { function render($ns, $directive, $value, $name, $config) { + $this->prepareGenerator($config); // this should probably be split up a little $ret = ''; $def = $config->def->info[$ns][$directive]; @@ -193,7 +208,6 @@ class HTMLPurifier_Printer_ConfigForm_default extends HTMLPurifier_Printer { $value = serialize($value); } $attr = array( - 'type' => 'text', 'name' => "$name"."[$ns.$directive]", 'id' => "$name:$ns.$directive" ); @@ -208,6 +222,7 @@ class HTMLPurifier_Printer_ConfigForm_default extends HTMLPurifier_Printer { $ret .= $this->end('select'); } else { $attr['value'] = $value; + $attr['type'] = 'text'; $ret .= $this->elementEmpty('input', $attr); } return $ret; @@ -219,8 +234,8 @@ class HTMLPurifier_Printer_ConfigForm_default extends HTMLPurifier_Printer { */ class HTMLPurifier_Printer_ConfigForm_bool extends HTMLPurifier_Printer { function render($ns, $directive, $value, $name, $config) { + $this->prepareGenerator($config); $ret = ''; - $ret .= $this->start('div', array('id' => "$name:$ns.$directive")); $ret .= $this->start('label', array('for' => "$name:Yes_$ns.$directive")); @@ -257,4 +272,3 @@ class HTMLPurifier_Printer_ConfigForm_bool extends HTMLPurifier_Printer { } } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/Printer/HTMLDefinition.php b/library/HTMLPurifier/Printer/HTMLDefinition.php index a677c58b..52650c63 100644 --- a/library/HTMLPurifier/Printer/HTMLDefinition.php +++ b/library/HTMLPurifier/Printer/HTMLDefinition.php @@ -15,9 +15,44 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer $this->config =& $config; $this->def = $config->getHTMLDefinition(); - $def =& $this->def; $ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer')); + + $ret .= $this->renderDoctype(); + $ret .= $this->renderEnvironment(); + $ret .= $this->renderContentSets(); + $ret .= $this->renderInfo(); + + $ret .= $this->end('div'); + + return $ret; + } + + /** + * Renders the Doctype table + */ + function renderDoctype() { + $doctype = $this->def->doctype; + $ret = ''; + $ret .= $this->start('table'); + $ret .= $this->element('caption', 'Doctype'); + $ret .= $this->row('Name', $doctype->name); + $ret .= $this->row('XML', $doctype->xml ? 'Yes' : 'No'); + $ret .= $this->row('Default Modules', implode($doctype->modules, ', ')); + $ret .= $this->row('Default Tidy Modules', implode($doctype->tidyModules, ', ')); + $ret .= $this->end('table'); + return $ret; + } + + + /** + * Renders environment table, which is miscellaneous info + */ + function renderEnvironment() { + $def = $this->def; + + $ret = ''; + $ret .= $this->start('table'); $ret .= $this->element('caption', 'Environment'); @@ -51,13 +86,22 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer $ret .= $this->end('tr'); $ret .= $this->end('table'); - - - $ret .= $this->renderInfo(); - - - $ret .= $this->end('div'); - + return $ret; + } + + /** + * Renders the Content Sets table + */ + function renderContentSets() { + $ret = ''; + $ret .= $this->start('table'); + $ret .= $this->element('caption', 'Content Sets'); + foreach ($this->def->info_content_sets as $name => $lookup) { + $ret .= $this->heavyHeader($name); + $ret .= $this->start('tr'); + $ret .= $this->element('td', $this->listifyTagLookup($lookup)); + $ret .= $this->end('tr'); + } return $ret; } @@ -69,15 +113,13 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer $ret .= $this->start('table'); $ret .= $this->element('caption', 'Elements ($info)'); ksort($this->def->info); - $ret .= $this->start('tr'); - $ret .= $this->element('th', 'Allowed tags', array('colspan' => 2, 'class' => 'heavy')); - $ret .= $this->end('tr'); + $ret .= $this->heavyHeader('Allowed tags', 2); $ret .= $this->start('tr'); $ret .= $this->element('td', $this->listifyTagLookup($this->def->info), array('colspan' => 2)); $ret .= $this->end('tr'); foreach ($this->def->info as $name => $def) { $ret .= $this->start('tr'); - $ret .= $this->element('th', "<$name>", array('class'=>'heavy', 'colspan' => 2)); + $ret .= $this->element('th', "<$name>" . ($def->safe ? '' : ' (unsafe)'), array('class'=>'heavy' . ($def->safe ? '' : ' unsafe'), 'colspan' => 2)); $ret .= $this->end('tr'); $ret .= $this->start('tr'); $ret .= $this->element('th', 'Inline content'); @@ -109,9 +151,13 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer } $ret .= $this->start('tr'); $ret .= $this->element('th', 'Allowed attributes'); - $ret .= $this->element('td',$this->listifyAttr($def->attr),0,0); + $ret .= $this->element('td',$this->listifyAttr($def->attr), array(), 0); $ret .= $this->end('tr'); + if (!empty($def->required_attr)) { + $ret .= $this->row('Required attributes', $this->listify($def->required_attr)); + } + $ret .= $this->renderChildren($def->child); } $ret .= $this->end('table'); @@ -154,6 +200,11 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer 'Inline: ' . $this->escape($this->listifyTagLookup($def->inline->elements)),0,0); + } elseif ($def->type == 'custom') { + + $ret .= $this->element('td', ''.ucfirst($def->type).': ' . + $def->dtd_regex); + } else { $ret .= $this->element('td', ''.ucfirst($def->type).': ' . @@ -205,6 +256,16 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer return $this->listify($list); } + /** + * Creates a heavy header row + */ + function heavyHeader($text, $num = 1) { + $ret = ''; + $ret .= $this->start('tr'); + $ret .= $this->element('th', $text, array('colspan' => $num, 'class' => 'heavy')); + $ret .= $this->end('tr'); + return $ret; + } + } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/Strategy.php b/library/HTMLPurifier/Strategy.php index 746b0a2d..a6ab7e8b 100644 --- a/library/HTMLPurifier/Strategy.php +++ b/library/HTMLPurifier/Strategy.php @@ -30,4 +30,3 @@ class HTMLPurifier_Strategy } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/Strategy/Composite.php b/library/HTMLPurifier/Strategy/Composite.php index bd868747..fcd230f4 100644 --- a/library/HTMLPurifier/Strategy/Composite.php +++ b/library/HTMLPurifier/Strategy/Composite.php @@ -27,4 +27,3 @@ class HTMLPurifier_Strategy_Composite extends HTMLPurifier_Strategy } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/Strategy/Core.php b/library/HTMLPurifier/Strategy/Core.php index 66e7bb36..93d05104 100644 --- a/library/HTMLPurifier/Strategy/Core.php +++ b/library/HTMLPurifier/Strategy/Core.php @@ -22,4 +22,3 @@ class HTMLPurifier_Strategy_Core extends HTMLPurifier_Strategy_Composite } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/Strategy/FixNesting.php b/library/HTMLPurifier/Strategy/FixNesting.php index e6a779e5..51a14a78 100644 --- a/library/HTMLPurifier/Strategy/FixNesting.php +++ b/library/HTMLPurifier/Strategy/FixNesting.php @@ -54,6 +54,9 @@ class HTMLPurifier_Strategy_FixNesting extends HTMLPurifier_Strategy $is_inline = $definition->info_parent_def->descendants_are_inline; $context->register('IsInline', $is_inline); + // setup error collector + $e =& $context->get('ErrorCollector', true); + //####################################################################// // Loop initialization @@ -67,6 +70,11 @@ class HTMLPurifier_Strategy_FixNesting extends HTMLPurifier_Strategy // processed, i.e. there won't be empty exclusions. $exclude_stack = array(); + // variable that contains the start token while we are processing + // nodes. This enables error reporting to do its job + $start_token = false; + $context->register('CurrentToken', $start_token); + //####################################################################// // Loop @@ -100,6 +108,8 @@ class HTMLPurifier_Strategy_FixNesting extends HTMLPurifier_Strategy // $i is index of start token // $j is index of end token + $start_token = $tokens[$i]; // to make token available via CurrentToken + //################################################################// // Gather information on parent @@ -200,6 +210,14 @@ class HTMLPurifier_Strategy_FixNesting extends HTMLPurifier_Strategy } elseif($result === false) { // remove entire node + if ($e) { + if ($excluded) { + $e->send(E_ERROR, 'Strategy_FixNesting: Node excluded'); + } else { + $e->send(E_ERROR, 'Strategy_FixNesting: Node removed'); + } + } + // calculate length of inner tokens and current tokens $length = $j - $i + 1; @@ -216,7 +234,7 @@ class HTMLPurifier_Strategy_FixNesting extends HTMLPurifier_Strategy // this is a rought heuristic that covers 100% of HTML's // cases and 99% of all other cases. A child definition // that would be tricked by this would be something like: - // ( | a b c) where it's all or nothing. Fortunantely, + // ( | a b c) where it's all or nothing. Fortunately, // our current implementation claims that that case would // not allow empty, even if it did if (!$parent_def->child->allow_empty) { @@ -234,6 +252,14 @@ class HTMLPurifier_Strategy_FixNesting extends HTMLPurifier_Strategy // calculate length of inner tokens $length = $j - $i - 1; + if ($e) { + if (empty($result) && $length) { + $e->send(E_ERROR, 'Strategy_FixNesting: Node contents removed'); + } else { + $e->send(E_WARNING, 'Strategy_FixNesting: Node reorganized'); + } + } + // perform replacement array_splice($tokens, $i + 1, $length, $result); @@ -291,6 +317,7 @@ class HTMLPurifier_Strategy_FixNesting extends HTMLPurifier_Strategy // remove context variables $context->destroy('IsInline'); + $context->destroy('CurrentToken'); //####################################################################// // Return @@ -301,4 +328,4 @@ class HTMLPurifier_Strategy_FixNesting extends HTMLPurifier_Strategy } -?> + diff --git a/library/HTMLPurifier/Strategy/MakeWellFormed.php b/library/HTMLPurifier/Strategy/MakeWellFormed.php index 9d440452..3a8109cf 100644 --- a/library/HTMLPurifier/Strategy/MakeWellFormed.php +++ b/library/HTMLPurifier/Strategy/MakeWellFormed.php @@ -4,129 +4,229 @@ require_once 'HTMLPurifier/Strategy.php'; require_once 'HTMLPurifier/HTMLDefinition.php'; require_once 'HTMLPurifier/Generator.php'; +require_once 'HTMLPurifier/Injector/AutoParagraph.php'; +require_once 'HTMLPurifier/Injector/Linkify.php'; +require_once 'HTMLPurifier/Injector/PurifierLinkify.php'; + +HTMLPurifier_ConfigSchema::define( + 'AutoFormat', 'Custom', array(), 'list', ' +

+ This directive can be used to add custom auto-format injectors. + Specify an array of injector names (class name minus the prefix) + or concrete implementations. Injector class must exist. This directive + has been available since 2.0.1. +

+' +); + /** * Takes tokens makes them well-formed (balance end tags, etc.) */ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy { + /** + * Locally shared variable references + * @private + */ + var $inputTokens, $inputIndex, $outputTokens, $currentNesting, + $currentInjector, $injectors; + function execute($tokens, $config, &$context) { + $definition = $config->getHTMLDefinition(); - $generator = new HTMLPurifier_Generator(); + + // CurrentNesting + $this->currentNesting = array(); + $context->register('CurrentNesting', $this->currentNesting); + + // InputIndex + $this->inputIndex = false; + $context->register('InputIndex', $this->inputIndex); + + // InputTokens + $context->register('InputTokens', $tokens); + $this->inputTokens =& $tokens; + + // OutputTokens $result = array(); - $current_nesting = array(); + $this->outputTokens =& $result; + + // %Core.EscapeInvalidTags $escape_invalid_tags = $config->get('Core', 'EscapeInvalidTags'); - foreach ($tokens as $token) { + $generator = new HTMLPurifier_Generator(); + + $e =& $context->get('ErrorCollector', true); + + // -- begin INJECTOR -- + + $this->injectors = array(); + + $injectors = $config->getBatch('AutoFormat'); + $custom_injectors = $injectors['Custom']; + unset($injectors['Custom']); // special case + foreach ($injectors as $injector => $b) { + $injector = "HTMLPurifier_Injector_$injector"; + if ($b) $this->injectors[] = new $injector; + } + foreach ($custom_injectors as $injector) { + if (is_string($injector)) { + $injector = "HTMLPurifier_Injector_$injector"; + $injector = new $injector; + } + $this->injectors[] = $injector; + } + + // array index of the injector that resulted in an array + // substitution. This enables processTokens() to know which + // injectors are affected by the added tokens and which are + // not (namely, the ones after the current injector are not + // affected) + $this->currentInjector = false; + + // give the injectors references to the definition and context + // variables for performance reasons + foreach ($this->injectors as $i => $x) { + $this->injectors[$i]->prepare($config, $context); + } + + // -- end INJECTOR -- + + $token = false; + $context->register('CurrentToken', $token); + + for ($this->inputIndex = 0; isset($tokens[$this->inputIndex]); $this->inputIndex++) { + + // if all goes well, this token will be passed through unharmed + $token = $tokens[$this->inputIndex]; + + foreach ($this->injectors as $i => $x) { + if ($x->skip > 0) $this->injectors[$i]->skip--; + } + + // quick-check: if it's not a tag, no need to process if (empty( $token->is_tag )) { - $result[] = $token; + if ($token->type === 'text') { + // injector handler code; duplicated for performance reasons + foreach ($this->injectors as $i => $x) { + if (!$x->skip) $x->handleText($token, $config, $context); + if (is_array($token)) { + $this->currentInjector = $i; + break; + } + } + } + $this->processToken($token, $config, $context); continue; } - // DEFINITION CALL $info = $definition->info[$token->name]->child; + // quick checks: // test if it claims to be a start tag but is empty - if ($info->type == 'empty' && - $token->type == 'start' ) { - - $result[] = new HTMLPurifier_Token_Empty($token->name, - $token->attr); + if ($info->type == 'empty' && $token->type == 'start') { + $result[] = new HTMLPurifier_Token_Empty($token->name, $token->attr); continue; } - // test if it claims to be empty but really is a start tag - if ($info->type != 'empty' && - $token->type == 'empty' ) { - - $result[] = new HTMLPurifier_Token_Start($token->name, - $token->attr); + if ($info->type != 'empty' && $token->type == 'empty' ) { + $result[] = new HTMLPurifier_Token_Start($token->name, $token->attr); $result[] = new HTMLPurifier_Token_End($token->name); - continue; } - // automatically insert empty tags if ($token->type == 'empty') { $result[] = $token; continue; } - // we give start tags precedence, so automatically accept unless... - // it's one of those special cases + // start tags have precedence, so they get passed through... if ($token->type == 'start') { - // if there's a parent, check for special case - if (!empty($current_nesting)) { + // ...unless they also have to close their parent + if (!empty($this->currentNesting)) { - $parent = array_pop($current_nesting); - $parent_name = $parent->name; - $parent_info = $definition->info[$parent_name]; + $parent = array_pop($this->currentNesting); + $parent_info = $definition->info[$parent->name]; - // we need to replace this with a more general - // algorithm - if (isset($parent_info->auto_close[$token->name])) { - $result[] = new HTMLPurifier_Token_End($parent_name); + // this can be replaced with a more general algorithm: + // if the token is not allowed by the parent, auto-close + // the parent + if (!isset($parent_info->child->elements[$token->name])) { + if ($e) $e->send(E_NOTICE, 'Strategy_MakeWellFormed: Tag auto closed', $parent); + // close the parent, then append the token + $result[] = new HTMLPurifier_Token_End($parent->name); $result[] = $token; - $current_nesting[] = $token; + $this->currentNesting[] = $token; continue; } - $current_nesting[] = $parent; // undo the pop + $this->currentNesting[] = $parent; // undo the pop } - $result[] = $token; - $current_nesting[] = $token; + // injector handler code; duplicated for performance reasons + foreach ($this->injectors as $i => $x) { + if (!$x->skip) $x->handleStart($token, $config, $context); + if (is_array($token)) { + $this->currentInjector = $i; + break; + } + } + + $this->processToken($token, $config, $context); continue; } - // sanity check + // sanity check: we should be dealing with a closing tag if ($token->type != 'end') continue; - // okay, we're dealing with a closing tag - // make sure that we have something open - if (empty($current_nesting)) { + if (empty($this->currentNesting)) { if ($escape_invalid_tags) { + if ($e) $e->send(E_WARNING, 'Strategy_MakeWellFormed: Unnecessary end tag to text'); $result[] = new HTMLPurifier_Token_Text( $generator->generateFromToken($token, $config, $context) ); + } elseif ($e) { + $e->send(E_WARNING, 'Strategy_MakeWellFormed: Unnecessary end tag removed'); } continue; } // first, check for the simplest case: everything closes neatly - - // current_nesting is modified - $current_parent = array_pop($current_nesting); + $current_parent = array_pop($this->currentNesting); if ($current_parent->name == $token->name) { $result[] = $token; continue; } - // undo the array_pop - $current_nesting[] = $current_parent; - // okay, so we're trying to close the wrong tag - // scroll back the entire nest, trying to find our tag - // feature could be to specify how far you'd like to go - $size = count($current_nesting); + // undo the pop previous pop + $this->currentNesting[] = $current_parent; + + // scroll back the entire nest, trying to find our tag. + // (feature could be to specify how far you'd like to go) + $size = count($this->currentNesting); // -2 because -1 is the last element, but we already checked that $skipped_tags = false; for ($i = $size - 2; $i >= 0; $i--) { - if ($current_nesting[$i]->name == $token->name) { + if ($this->currentNesting[$i]->name == $token->name) { // current nesting is modified - $skipped_tags = array_splice($current_nesting, $i); + $skipped_tags = array_splice($this->currentNesting, $i); break; } } - // we still didn't find the tag, so translate to text + // we still didn't find the tag, so remove if ($skipped_tags === false) { if ($escape_invalid_tags) { $result[] = new HTMLPurifier_Token_Text( $generator->generateFromToken($token, $config, $context) ); + if ($e) $e->send(E_WARNING, 'Strategy_MakeWellFormed: Stray end tag to text'); + } elseif ($e) { + $e->send(E_WARNING, 'Strategy_MakeWellFormed: Stray end tag removed'); } continue; } @@ -134,27 +234,66 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy // okay, we found it, close all the skipped tags // note that skipped tags contains the element we need closed $size = count($skipped_tags); - for ($i = $size - 1; $i >= 0; $i--) { + for ($i = $size - 1; $i > 0; $i--) { + if ($e && !isset($skipped_tags[$i]->armor['MakeWellFormed_TagClosedError'])) { + $e->send(E_NOTICE, 'Strategy_MakeWellFormed: Tag closed by element end', $skipped_tags[$i]); + } $result[] = new HTMLPurifier_Token_End($skipped_tags[$i]->name); } - // done! + $result[] = new HTMLPurifier_Token_End($skipped_tags[$i]->name); } - // we're at the end now, fix all still unclosed tags + $context->destroy('CurrentNesting'); + $context->destroy('InputTokens'); + $context->destroy('InputIndex'); + $context->destroy('CurrentToken'); - if (!empty($current_nesting)) { - $size = count($current_nesting); + // we're at the end now, fix all still unclosed tags + // not using processToken() because at this point we don't + // care about current nesting + if (!empty($this->currentNesting)) { + $size = count($this->currentNesting); for ($i = $size - 1; $i >= 0; $i--) { + if ($e && !isset($this->currentNesting[$i]->armor['MakeWellFormed_TagClosedError'])) { + $e->send(E_NOTICE, 'Strategy_MakeWellFormed: Tag closed by document end', $this->currentNesting[$i]); + } $result[] = - new HTMLPurifier_Token_End($current_nesting[$i]->name); + new HTMLPurifier_Token_End($this->currentNesting[$i]->name); } } + unset($this->outputTokens, $this->injectors, $this->currentInjector, + $this->currentNesting, $this->inputTokens, $this->inputIndex); + return $result; } + function processToken($token, $config, &$context) { + if (is_array($token)) { + // the original token was overloaded by an injector, time + // to some fancy acrobatics + + // $this->inputIndex is decremented so that the entire set gets + // re-processed + array_splice($this->inputTokens, $this->inputIndex--, 1, $token); + + // adjust the injector skips based on the array substitution + $offset = count($token) + 1; + for ($i = 0; $i <= $this->currentInjector; $i++) { + $this->injectors[$i]->skip += $offset; + } + } elseif ($token) { + // regular case + $this->outputTokens[] = $token; + if ($token->type == 'start') { + $this->currentNesting[] = $token; + } elseif ($token->type == 'end') { + array_pop($this->currentNesting); // not actually used + } + } + } + } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/Strategy/RemoveForeignElements.php b/library/HTMLPurifier/Strategy/RemoveForeignElements.php index 9a1e80c0..c14662c3 100644 --- a/library/HTMLPurifier/Strategy/RemoveForeignElements.php +++ b/library/HTMLPurifier/Strategy/RemoveForeignElements.php @@ -17,9 +17,11 @@ HTMLPurifier_ConfigSchema::define( HTMLPurifier_ConfigSchema::define( 'Core', 'RemoveScriptContents', true, 'bool', ' -This directive enables HTML Purifier to remove not only script tags -but all of their contents. This directive has been available since 2.0.0, -revert to pre-2.0.0 behavior by setting to false. +

+ This directive enables HTML Purifier to remove not only script tags + but all of their contents. This directive has been available since 2.0.0, + revert to pre-2.0.0 behavior by setting to false. +

' ); @@ -48,6 +50,17 @@ class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy // removes tokens until it reaches a closing tag with its value $remove_until = false; + // converts comments into text tokens when this is equal to a tag name + $textify_comments = false; + + $token = false; + $context->register('CurrentToken', $token); + + $e = false; + if ($config->get('Core', 'CollectErrors')) { + $e =& $context->get('ErrorCollector'); + } + foreach($tokens as $token) { if ($remove_until) { if (empty($token->is_tag) || $token->name !== $remove_until) { @@ -61,11 +74,13 @@ class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy if ( isset($definition->info_tag_transform[$token->name]) ) { + $original_name = $token->name; // there is a transformation for this tag // DEFINITION CALL $token = $definition-> info_tag_transform[$token->name]-> transform($token, $config, $context); + if ($e) $e->send(E_NOTICE, 'Strategy_RemoveForeignElements: Tag transform', $original_name); } if (isset($definition->info[$token->name])) { @@ -76,7 +91,7 @@ class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy $definition->info[$token->name]->required_attr && ($token->name != 'img' || $remove_invalid_img) // ensure config option still works ) { - $token = $attr_validator->validateToken($token, $config, $context); + $attr_validator->validateToken($token, $config, $context); $ok = true; foreach ($definition->info[$token->name]->required_attr as $name) { if (!isset($token->attr[$name])) { @@ -84,12 +99,23 @@ class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy break; } } - if (!$ok) continue; + if (!$ok) { + if ($e) $e->send(E_ERROR, 'Strategy_RemoveForeignElements: Missing required attribute', $name); + continue; + } $token->armor['ValidateAttributes'] = true; } + // CAN BE GENERICIZED + if ($token->name == 'script' && $token->type == 'start') { + $textify_comments = $token->name; + } elseif ($token->name === $textify_comments && $token->type == 'end') { + $textify_comments = false; + } + } elseif ($escape_invalid_tags) { - // invalid tag, generate HTML and insert in + // invalid tag, generate HTML representation and insert in + if ($e) $e->send(E_WARNING, 'Strategy_RemoveForeignElements: Foreign element to text'); $token = new HTMLPurifier_Token_Text( $generator->generateFromToken($token, $config, $context) ); @@ -104,21 +130,37 @@ class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy } else { $remove_until = false; } + if ($e) $e->send(E_ERROR, 'Strategy_RemoveForeignElements: Script removed'); + } else { + if ($e) $e->send(E_ERROR, 'Strategy_RemoveForeignElements: Foreign element removed'); } continue; } } elseif ($token->type == 'comment') { - // strip comments - continue; + // textify comments in script tags when they are allowed + if ($textify_comments !== false) { + $data = $token->data; + $token = new HTMLPurifier_Token_Text($data); + } else { + // strip comments + if ($e) $e->send(E_NOTICE, 'Strategy_RemoveForeignElements: Comment removed'); + continue; + } } elseif ($token->type == 'text') { } else { continue; } $result[] = $token; } + if ($remove_until && $e) { + // we removed tokens until the end, throw error + $e->send(E_ERROR, 'Strategy_RemoveForeignElements: Token removed to end', $remove_until); + } + + $context->destroy('CurrentToken'); + return $result; } } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/Strategy/ValidateAttributes.php b/library/HTMLPurifier/Strategy/ValidateAttributes.php index 1c9e09b3..4b3d7486 100644 --- a/library/HTMLPurifier/Strategy/ValidateAttributes.php +++ b/library/HTMLPurifier/Strategy/ValidateAttributes.php @@ -27,6 +27,9 @@ class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy // setup validator $validator = new HTMLPurifier_AttrValidator(); + $token = false; + $context->register('CurrentToken', $token); + foreach ($tokens as $key => $token) { // only process tokens that have attributes, @@ -36,7 +39,10 @@ class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy // skip tokens that are armored if (!empty($token->armor['ValidateAttributes'])) continue; - $tokens[$key] = $validator->validateToken($token, $config, $context); + // note that we have no facilities here for removing tokens + $validator->validateToken($token, $config, $context); + + $tokens[$key] = $token; // for PHP 4 } $context->destroy('IDAccumulator'); @@ -46,4 +52,3 @@ class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/TagTransform.php b/library/HTMLPurifier/TagTransform.php index 367ec8be..f5de99ce 100644 --- a/library/HTMLPurifier/TagTransform.php +++ b/library/HTMLPurifier/TagTransform.php @@ -38,4 +38,3 @@ class HTMLPurifier_TagTransform } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/TagTransform/Font.php b/library/HTMLPurifier/TagTransform/Font.php index dedaf8b2..5bc22df9 100644 --- a/library/HTMLPurifier/TagTransform/Font.php +++ b/library/HTMLPurifier/TagTransform/Font.php @@ -39,7 +39,8 @@ class HTMLPurifier_TagTransform_Font extends HTMLPurifier_TagTransform function transform($tag, $config, &$context) { if ($tag->type == 'end') { - $new_tag = new HTMLPurifier_Token_End($this->transform_to); + $new_tag = $tag->copy(); + $new_tag->name = $this->transform_to; return $new_tag; } @@ -91,4 +92,3 @@ class HTMLPurifier_TagTransform_Font extends HTMLPurifier_TagTransform } } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/TagTransform/Simple.php b/library/HTMLPurifier/TagTransform/Simple.php index f8299e11..0b5a84d4 100644 --- a/library/HTMLPurifier/TagTransform/Simple.php +++ b/library/HTMLPurifier/TagTransform/Simple.php @@ -34,4 +34,3 @@ class HTMLPurifier_TagTransform_Simple extends HTMLPurifier_TagTransform } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/Token.php b/library/HTMLPurifier/Token.php index dfcc5cbc..bd859d7f 100644 --- a/library/HTMLPurifier/Token.php +++ b/library/HTMLPurifier/Token.php @@ -15,7 +15,8 @@ class HTMLPurifier_Token { /** * Lookup array of processing that this token is exempt from. - * Currently, the only valid value is "ValidateAttributes". + * Currently, valid values are "ValidateAttributes" and + * "MakeWellFormed_TagClosedError" */ var $armor = array(); @@ -24,7 +25,7 @@ class HTMLPurifier_Token { * @return Copied token */ function copy() { - trigger_error('Cannot copy abstract class', E_USER_ERROR); + return unserialize(serialize($this)); } } @@ -65,7 +66,7 @@ class HTMLPurifier_Token_Tag extends HTMLPurifier_Token // abstract * @param $name String name. * @param $attr Associative array of attributes. */ - function HTMLPurifier_Token_Tag($name, $attr = array()) { + function HTMLPurifier_Token_Tag($name, $attr = array(), $line = null) { $this->name = ctype_lower($name) ? $name : strtolower($name); foreach ($attr as $key => $value) { // normalization only necessary when key is not lowercase @@ -80,6 +81,7 @@ class HTMLPurifier_Token_Tag extends HTMLPurifier_Token // abstract } } $this->attr = $attr; + $this->line = $line; } } @@ -89,9 +91,6 @@ class HTMLPurifier_Token_Tag extends HTMLPurifier_Token // abstract class HTMLPurifier_Token_Start extends HTMLPurifier_Token_Tag { var $type = 'start'; - function copy() { - return new HTMLPurifier_Token_Start($this->name, $this->attr); - } } /** @@ -100,9 +99,6 @@ class HTMLPurifier_Token_Start extends HTMLPurifier_Token_Tag class HTMLPurifier_Token_Empty extends HTMLPurifier_Token_Tag { var $type = 'empty'; - function copy() { - return new HTMLPurifier_Token_Empty($this->name, $this->attr); - } } /** @@ -115,9 +111,6 @@ class HTMLPurifier_Token_Empty extends HTMLPurifier_Token_Tag class HTMLPurifier_Token_End extends HTMLPurifier_Token_Tag { var $type = 'end'; - function copy() { - return new HTMLPurifier_Token_End($this->name); - } } /** @@ -142,12 +135,10 @@ class HTMLPurifier_Token_Text extends HTMLPurifier_Token * * @param $data String parsed character data. */ - function HTMLPurifier_Token_Text($data) { + function HTMLPurifier_Token_Text($data, $line = null) { $this->data = $data; $this->is_whitespace = ctype_space($data); - } - function copy() { - return new HTMLPurifier_Token_Text($this->data); + $this->line = $line; } } @@ -164,12 +155,9 @@ class HTMLPurifier_Token_Comment extends HTMLPurifier_Token * * @param $data String comment data. */ - function HTMLPurifier_Token_Comment($data) { + function HTMLPurifier_Token_Comment($data, $line = null) { $this->data = $data; - } - function copy() { - return new HTMLPurifier_Token_Comment($this->data); + $this->line = $line; } } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/TokenFactory.php b/library/HTMLPurifier/TokenFactory.php index 25cc4122..d15ee1a9 100644 --- a/library/HTMLPurifier/TokenFactory.php +++ b/library/HTMLPurifier/TokenFactory.php @@ -93,4 +93,3 @@ class HTMLPurifier_TokenFactory } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/URIScheme.php b/library/HTMLPurifier/URIScheme.php index 20a9781b..9be99752 100644 --- a/library/HTMLPurifier/URIScheme.php +++ b/library/HTMLPurifier/URIScheme.php @@ -41,4 +41,3 @@ class HTMLPurifier_URIScheme } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/URIScheme/ftp.php b/library/HTMLPurifier/URIScheme/ftp.php index dab9c981..3dbb1446 100644 --- a/library/HTMLPurifier/URIScheme/ftp.php +++ b/library/HTMLPurifier/URIScheme/ftp.php @@ -42,4 +42,3 @@ class HTMLPurifier_URIScheme_ftp extends HTMLPurifier_URIScheme { } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/URIScheme/http.php b/library/HTMLPurifier/URIScheme/http.php index 54b250da..18a1cf87 100644 --- a/library/HTMLPurifier/URIScheme/http.php +++ b/library/HTMLPurifier/URIScheme/http.php @@ -21,4 +21,3 @@ class HTMLPurifier_URIScheme_http extends HTMLPurifier_URIScheme { } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/URIScheme/https.php b/library/HTMLPurifier/URIScheme/https.php index 7f896592..bbd69b9c 100644 --- a/library/HTMLPurifier/URIScheme/https.php +++ b/library/HTMLPurifier/URIScheme/https.php @@ -11,4 +11,3 @@ class HTMLPurifier_URIScheme_https extends HTMLPurifier_URIScheme_http { } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/URIScheme/mailto.php b/library/HTMLPurifier/URIScheme/mailto.php index 2292072e..8e552f5c 100644 --- a/library/HTMLPurifier/URIScheme/mailto.php +++ b/library/HTMLPurifier/URIScheme/mailto.php @@ -27,4 +27,3 @@ class HTMLPurifier_URIScheme_mailto extends HTMLPurifier_URIScheme { } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/URIScheme/news.php b/library/HTMLPurifier/URIScheme/news.php index c9d1c2b0..7b81834f 100644 --- a/library/HTMLPurifier/URIScheme/news.php +++ b/library/HTMLPurifier/URIScheme/news.php @@ -21,4 +21,3 @@ class HTMLPurifier_URIScheme_news extends HTMLPurifier_URIScheme { } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/URIScheme/nntp.php b/library/HTMLPurifier/URIScheme/nntp.php index 49fca4c3..8f513419 100644 --- a/library/HTMLPurifier/URIScheme/nntp.php +++ b/library/HTMLPurifier/URIScheme/nntp.php @@ -21,4 +21,3 @@ class HTMLPurifier_URIScheme_nntp extends HTMLPurifier_URIScheme { } -?> \ No newline at end of file diff --git a/library/HTMLPurifier/URISchemeRegistry.php b/library/HTMLPurifier/URISchemeRegistry.php index 1ece1a2a..5d8c462c 100644 --- a/library/HTMLPurifier/URISchemeRegistry.php +++ b/library/HTMLPurifier/URISchemeRegistry.php @@ -101,4 +101,4 @@ class HTMLPurifier_URISchemeRegistry } -?> + diff --git a/maintenance/flush-htmldefinition-cache.php b/maintenance/flush-htmldefinition-cache.php index 780be373..c6d31bfb 100644 --- a/maintenance/flush-htmldefinition-cache.php +++ b/maintenance/flush-htmldefinition-cache.php @@ -21,4 +21,3 @@ $cache->flush($config); echo 'Cache flushed successfully.'; -?> \ No newline at end of file diff --git a/maintenance/generate-entity-file.php b/maintenance/generate-entity-file.php index 8bf34a31..062fed1c 100644 --- a/maintenance/generate-entity-file.php +++ b/maintenance/generate-entity-file.php @@ -71,4 +71,3 @@ fclose($fh); echo "Completed successfully."; -?> \ No newline at end of file diff --git a/package.php b/package.php index 06a50514..c47e4c1b 100644 --- a/package.php +++ b/package.php @@ -53,4 +53,3 @@ $compat =& $pkg->exportCompatiblePackageFile1(); $compat->writePackageFile(); $pkg->writePackageFile(); -?> \ No newline at end of file diff --git a/release1-update.php b/release1-update.php index 05b6b904..4d51ab3a 100644 --- a/release1-update.php +++ b/release1-update.php @@ -92,4 +92,3 @@ file_put_contents('library/HTMLPurifier/Config.php', $config_c); echo "Review changes, write something in WHATSNEW, and then SVN commit with log 'Release $version.'" . PHP_EOL; -?> \ No newline at end of file diff --git a/release2-strict.php b/release2-strict.php index 4a8b8fd9..51e8aa98 100644 --- a/release2-strict.php +++ b/release2-strict.php @@ -28,4 +28,3 @@ foreach ($out as $line) { $version = trim(file_get_contents('VERSION')); echo "Resolve conflicts and then commit as 'Release $version, merged in $last_rev to HEAD.'"; -?> \ No newline at end of file diff --git a/release3-tag.php b/release3-tag.php index c6f72758..3c0a4ee9 100644 --- a/release3-tag.php +++ b/release3-tag.php @@ -23,4 +23,3 @@ passthru("svn copy --message \"Tag $version release.\" $trunk_url $trunk_tag_url echo "Tagging strict to tags/$version-strict..."; passthru("svn copy --message \"Tag $version-strict release.\" $strict_url $strict_tag_url"); -?> \ No newline at end of file diff --git a/smoketests/all.php b/smoketests/all.php index de09412c..3f514e84 100644 --- a/smoketests/all.php +++ b/smoketests/all.php @@ -38,4 +38,4 @@ while (false !== ($filename = readdir($dh))) { ?> - \ No newline at end of file + diff --git a/smoketests/attrTransform.php b/smoketests/attrTransform.php index 05f61813..e1cf7a42 100644 --- a/smoketests/attrTransform.php +++ b/smoketests/attrTransform.php @@ -66,4 +66,4 @@ foreach ($xml->group as $group) { ?> - \ No newline at end of file + diff --git a/smoketests/attrTransform.xml b/smoketests/attrTransform.xml index 74500488..ca0ee5b1 100644 --- a/smoketests/attrTransform.xml +++ b/smoketests/attrTransform.xml @@ -186,4 +186,4 @@ --> - \ No newline at end of file + diff --git a/smoketests/basic.php b/smoketests/basic.php index 7c791be5..e8ffed80 100644 --- a/smoketests/basic.php +++ b/smoketests/basic.php @@ -67,4 +67,4 @@ if ($page) { ?> - \ No newline at end of file + diff --git a/smoketests/basic/allElements.css b/smoketests/basic/allElements.css index 874c094c..58fb0546 100644 --- a/smoketests/basic/allElements.css +++ b/smoketests/basic/allElements.css @@ -45,4 +45,4 @@ div > * {background:#F00; color:#FFF; font-weight:bold; padding:0.2em; margin:0. .insert-declarations-above {background:#008000; margin:0; padding:0.2em;} #module-text span, #module-text div {padding:0; margin:0.1em;} -#module-list li, #module-list dd, #module-list dt {border:1px solid #FFF;} \ No newline at end of file +#module-list li, #module-list dd, #module-list dt {border:1px solid #FFF;} diff --git a/smoketests/basic/allElements.html b/smoketests/basic/allElements.html index a3fa408a..9f727258 100644 --- a/smoketests/basic/allElements.html +++ b/smoketests/basic/allElements.html @@ -76,4 +76,4 @@ otherwise there will be problems.

- \ No newline at end of file + diff --git a/smoketests/basic/legacy.html b/smoketests/basic/legacy.html index 00919734..30239379 100644 --- a/smoketests/basic/legacy.html +++ b/smoketests/basic/legacy.html @@ -121,4 +121,4 @@ hr@size - \ No newline at end of file + diff --git a/smoketests/common.php b/smoketests/common.php index c9b09dbf..8b3785a9 100644 --- a/smoketests/common.php +++ b/smoketests/common.php @@ -11,4 +11,3 @@ function escapeHTML($string) { return $string; } -?> diff --git a/smoketests/configForm.php b/smoketests/configForm.php index 63385dc7..f84bb48d 100644 --- a/smoketests/configForm.php +++ b/smoketests/configForm.php @@ -70,8 +70,8 @@ echo $printer->render($config);
 getAll());
+echo htmlspecialchars(print_r($config->getAll(), true));
 ?>
 
- \ No newline at end of file + diff --git a/smoketests/loadFunc.php b/smoketests/loadFunc.php index d93cc0a7..bff9a879 100644 --- a/smoketests/loadFunc.php +++ b/smoketests/loadFunc.php @@ -37,4 +37,4 @@ not the library is lazy loaded.

HTMLPurifier class exists:

- \ No newline at end of file + diff --git a/smoketests/preserveYouTube.php b/smoketests/preserveYouTube.php index 24820f8d..342fb681 100644 --- a/smoketests/preserveYouTube.php +++ b/smoketests/preserveYouTube.php @@ -41,4 +41,4 @@ echo $youtube_purifier->purify($string); ?> - \ No newline at end of file + diff --git a/smoketests/printDefinition.php b/smoketests/printDefinition.php index 02552adb..86fd9494 100644 --- a/smoketests/printDefinition.php +++ b/smoketests/printDefinition.php @@ -6,24 +6,13 @@ require_once 'HTMLPurifier/Printer/HTMLDefinition.php'; require_once 'HTMLPurifier/Printer/CSSDefinition.php'; require_once 'HTMLPurifier/Printer/ConfigForm.php'; -$config = HTMLPurifier_Config::loadArrayFromForm($_GET, 'config'); +$config = HTMLPurifier_Config::loadArrayFromForm($_GET, 'config', 'HTML'); // you can do custom configuration! if (file_exists('printDefinition.settings.php')) { include 'printDefinition.settings.php'; } -/* // sample local definition, obviously needs to be less clunky -$html_definition =& $config->getHTMLDefinition(true); -$module = new HTMLPurifier_HTMLModule(); -$module->name = 'Marquee'; -$module->info['marquee'] = new HTMLPurifier_ElementDef(); -$module->info['marquee']->content_model = '#PCDATA | Inline'; -$module->info['marquee']->content_model_type = 'optional'; -$module->content_sets = array('Inline' => 'marquee'); -$html_definition->manager->addModule($module); -*/ - $printer_html_definition = new HTMLPurifier_Printer_HTMLDefinition(); $printer_css_definition = new HTMLPurifier_Printer_CSSDefinition(); @@ -33,6 +22,7 @@ $printer_config_form = new HTMLPurifier_Printer_ConfigForm( ); echo ''; + ?> @@ -51,6 +41,7 @@ echo ''; .HTMLPurifier_Printer caption {font-size:1.5em; font-weight:bold; width:100%;} .HTMLPurifier_Printer .heavy {background:#99C;text-align:center;} + .HTMLPurifier_Printer .unsafe {background:#C99;} dt {font-weight:bold;} @@ -120,4 +111,4 @@ Null/Disabled will mean that user whitelisting functionality is disabled.

CSSDefinition

render($config) ?> - \ No newline at end of file + diff --git a/smoketests/testSchema.php b/smoketests/testSchema.php dissimilarity index 70% index 1295566e..6e8bc74b 100644 --- a/smoketests/testSchema.php +++ b/smoketests/testSchema.php @@ -1,44 +1,39 @@ - true, '2' => true, '3' => true), 'lookup', - 'What numbers of neutrons for this element have been observed?'); -CS::define('Element', 'Traits', array('nonmetallic', 'odorless', 'flammable'), 'list', - 'What are general properties of the element?'); -CS::define('Element', 'IsotopeNames', array('1' => 'protium', '2' => 'deuterium', '3' => 'tritium'), 'hash', - 'Lookup hash of neutron counts to formal names.'); - -CS::defineNamespace('Instrument', 'Of the musical type.'); - -CS::define('Instrument', 'Manufacturer', 'Yamaha', 'string', 'Who made it?'); -CS::defineAllowedValues('Instrument', 'Manufacturer', array( - 'Yamaha', 'Conn-Selmer', 'Vandoren', 'Laubin', 'Buffet', 'other')); -CS::defineValueAliases('Instrument', 'Manufacturer', array( - 'Selmer' => 'Conn-Selmer')); - -CS::define('Instrument', 'Family', 'woodwind', 'istring', 'What family is it?'); -CS::defineAllowedValues('Instrument', 'Family', array( - 'brass', 'woodwind', 'percussion', 'string', 'keyboard', 'electronic')); -CS::defineValueAliases('Instrument', 'Family', array( - 'synth' => 'electronic')); - -CS::defineNamespace('ReportCard', 'It is for grades.'); -CS::define('ReportCard', 'English', null, 'string/null', 'Grade from English class.'); -CS::define('ReportCard', 'Absences', 0, 'int', 'How many times missing from school?'); - -?> \ No newline at end of file + true, '2' => true, '3' => true), 'lookup', + 'What numbers of neutrons for this element have been observed?'); +HTMLPurifier_ConfigSchema::define('Element', 'Traits', array('nonmetallic', 'odorless', 'flammable'), 'list', + 'What are general properties of the element?'); +HTMLPurifier_ConfigSchema::define('Element', 'IsotopeNames', array('1' => 'protium', '2' => 'deuterium', '3' => 'tritium'), 'hash', + 'Lookup hash of neutron counts to formal names.'); + +HTMLPurifier_ConfigSchema::defineNamespace('Instrument', 'Of the musical type.'); + +HTMLPurifier_ConfigSchema::define('Instrument', 'Manufacturer', 'Yamaha', 'string', 'Who made it?'); +HTMLPurifier_ConfigSchema::defineAllowedValues('Instrument', 'Manufacturer', array( + 'Yamaha', 'Conn-Selmer', 'Vandoren', 'Laubin', 'Buffet', 'other')); +HTMLPurifier_ConfigSchema::defineValueAliases('Instrument', 'Manufacturer', array( + 'Selmer' => 'Conn-Selmer')); + +HTMLPurifier_ConfigSchema::define('Instrument', 'Family', 'woodwind', 'istring', 'What family is it?'); +HTMLPurifier_ConfigSchema::defineAllowedValues('Instrument', 'Family', array( + 'brass', 'woodwind', 'percussion', 'string', 'keyboard', 'electronic')); +HTMLPurifier_ConfigSchema::defineValueAliases('Instrument', 'Family', array( + 'synth' => 'electronic')); + +HTMLPurifier_ConfigSchema::defineNamespace('ReportCard', 'It is for grades.'); +HTMLPurifier_ConfigSchema::define('ReportCard', 'English', null, 'string/null', 'Grade from English class.'); +HTMLPurifier_ConfigSchema::define('ReportCard', 'Absences', 0, 'int', 'How many times missing from school?'); + diff --git a/smoketests/utf8.php b/smoketests/utf8.php index 2d23330b..97f1441f 100644 --- a/smoketests/utf8.php +++ b/smoketests/utf8.php @@ -37,4 +37,4 @@ in Purified. If Purified is mangled, there is likely trouble a-brewing in the library. If both are mangled, check to see that this file was not corrupted.

- \ No newline at end of file + diff --git a/smoketests/variableWidthAttack.php b/smoketests/variableWidthAttack.php index 5c256803..c4054f66 100644 --- a/smoketests/variableWidthAttack.php +++ b/smoketests/variableWidthAttack.php @@ -51,4 +51,4 @@ for ($i = 0; $i < 256; $i++) { removed, as well as escaping quotes outside of tags, this is a non-threat.

- \ No newline at end of file + diff --git a/smoketests/xssAttacks.php b/smoketests/xssAttacks.php index f5bb78bb..bd39cab2 100644 --- a/smoketests/xssAttacks.php +++ b/smoketests/xssAttacks.php @@ -93,4 +93,4 @@ foreach ($xml->attack as $attack) { - \ No newline at end of file + diff --git a/svn.php b/svn.php index db588754..c57e4483 100644 --- a/svn.php +++ b/svn.php @@ -11,4 +11,3 @@ function svn_info($dir) { return $svn_info; } -?> \ No newline at end of file diff --git a/test-settings.sample.php b/test-settings.sample.php index 1fbcfe4e..bd1f622b 100644 --- a/test-settings.sample.php +++ b/test-settings.sample.php @@ -14,4 +14,3 @@ $GLOBALS['HTMLPurifierTest']['Runs'] = 2; // Where is SimpleTest located? $simpletest_location = '/path/to/simpletest/'; -?> \ No newline at end of file diff --git a/tests/Debugger.php b/tests/Debugger.php index 0691eb24..0fccd041 100644 --- a/tests/Debugger.php +++ b/tests/Debugger.php @@ -54,6 +54,19 @@ function isInScopes($array = array()) { } /**#@-*/ +function printTokens($tokens, $index) { + $string = '
';
+    $generator = new HTMLPurifier_Generator();
+    foreach ($tokens as $i => $token) {
+        if ($index == $i) $string .= '[';
+        $string .= "$i";
+        $string .= $generator->escape($generator->generateFromToken($token));
+        if ($index == $i) $string .= ']';
+    }
+    $string .= '
'; + echo $string; +} + /** * The debugging singleton. Most interesting stuff happens here. */ @@ -145,4 +158,3 @@ class Debugger } -?> diff --git a/tests/HTMLPurifier/AttrCollectionsTest.php b/tests/HTMLPurifier/AttrCollectionsTest.php index 632f75ed..6420a6ac 100644 --- a/tests/HTMLPurifier/AttrCollectionsTest.php +++ b/tests/HTMLPurifier/AttrCollectionsTest.php @@ -18,7 +18,7 @@ class HTMLPurifier_AttrCollectionsTest extends UnitTestCase $collections = new HTMLPurifier_AttrCollectionsTest_NoConstructor(); - $types = new HTMLPurifier_AttrTypesMock($this); + $types = new HTMLPurifier_AttrTypesMock(); $modules = array(); @@ -68,7 +68,7 @@ class HTMLPurifier_AttrCollectionsTest extends UnitTestCase generate_mock_once('HTMLPurifier_AttrTypes'); - $types = new HTMLPurifier_AttrTypesMock($this); + $types = new HTMLPurifier_AttrTypesMock(); $collections = new HTMLPurifier_AttrCollections($types, array()); $collections->info = array( 'Core' => array(0 => array('Inclusion', 'Undefined'), 'attr-original' => 'Type'), @@ -106,7 +106,7 @@ class HTMLPurifier_AttrCollectionsTest extends UnitTestCase generate_mock_once('HTMLPurifier_AttrTypes'); - $types = new HTMLPurifier_AttrTypesMock($this); + $types = new HTMLPurifier_AttrTypesMock(); $collections = new HTMLPurifier_AttrCollections($types, array()); $attr = array( @@ -136,4 +136,3 @@ class HTMLPurifier_AttrCollectionsTest extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/CSS/BackgroundPositionTest.php b/tests/HTMLPurifier/AttrDef/CSS/BackgroundPositionTest.php index 911823f4..134df679 100644 --- a/tests/HTMLPurifier/AttrDef/CSS/BackgroundPositionTest.php +++ b/tests/HTMLPurifier/AttrDef/CSS/BackgroundPositionTest.php @@ -68,4 +68,3 @@ class HTMLPurifier_AttrDef_CSS_BackgroundPositionTest extends HTMLPurifier_AttrD } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/CSS/BackgroundTest.php b/tests/HTMLPurifier/AttrDef/CSS/BackgroundTest.php index d4db8493..7cd60d34 100644 --- a/tests/HTMLPurifier/AttrDef/CSS/BackgroundTest.php +++ b/tests/HTMLPurifier/AttrDef/CSS/BackgroundTest.php @@ -19,4 +19,3 @@ class HTMLPurifier_AttrDef_CSS_BackgroundTest extends HTMLPurifier_AttrDefHarnes } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/CSS/BorderTest.php b/tests/HTMLPurifier/AttrDef/CSS/BorderTest.php index 6e130e46..5eaceae4 100644 --- a/tests/HTMLPurifier/AttrDef/CSS/BorderTest.php +++ b/tests/HTMLPurifier/AttrDef/CSS/BorderTest.php @@ -19,4 +19,3 @@ class HTMLPurifier_AttrDef_CSS_BorderTest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/CSS/ColorTest.php b/tests/HTMLPurifier/AttrDef/CSS/ColorTest.php index 89afd121..030c6224 100644 --- a/tests/HTMLPurifier/AttrDef/CSS/ColorTest.php +++ b/tests/HTMLPurifier/AttrDef/CSS/ColorTest.php @@ -34,4 +34,3 @@ class HTMLPurifier_AttrDef_CSS_ColorTest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/CSS/CompositeTest.php b/tests/HTMLPurifier/AttrDef/CSS/CompositeTest.php index 037131fb..34abb35a 100644 --- a/tests/HTMLPurifier/AttrDef/CSS/CompositeTest.php +++ b/tests/HTMLPurifier/AttrDef/CSS/CompositeTest.php @@ -29,8 +29,8 @@ class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness // first test: value properly validates on first definition // so second def is never called - $def1 = new HTMLPurifier_AttrDefMock($this); - $def2 = new HTMLPurifier_AttrDefMock($this); + $def1 = new HTMLPurifier_AttrDefMock(); + $def2 = new HTMLPurifier_AttrDefMock(); $defs = array(&$def1, &$def2); $def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs); $input = 'FOOBAR'; @@ -48,8 +48,8 @@ class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness // second test, first def fails, second def works - $def1 = new HTMLPurifier_AttrDefMock($this); - $def2 = new HTMLPurifier_AttrDefMock($this); + $def1 = new HTMLPurifier_AttrDefMock(); + $def2 = new HTMLPurifier_AttrDefMock(); $defs = array(&$def1, &$def2); $def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs); $input = 'BOOMA'; @@ -68,8 +68,8 @@ class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness // third test, all fail, so composite faiils - $def1 = new HTMLPurifier_AttrDefMock($this); - $def2 = new HTMLPurifier_AttrDefMock($this); + $def1 = new HTMLPurifier_AttrDefMock(); + $def2 = new HTMLPurifier_AttrDefMock(); $defs = array(&$def1, &$def2); $def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs); $input = 'BOOMA'; @@ -90,4 +90,3 @@ class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/CSS/FontFamilyTest.php b/tests/HTMLPurifier/AttrDef/CSS/FontFamilyTest.php index a802d45f..861cbb32 100644 --- a/tests/HTMLPurifier/AttrDef/CSS/FontFamilyTest.php +++ b/tests/HTMLPurifier/AttrDef/CSS/FontFamilyTest.php @@ -21,4 +21,3 @@ class HTMLPurifier_AttrDef_CSS_FontFamilyTest extends HTMLPurifier_AttrDefHarnes } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/CSS/FontTest.php b/tests/HTMLPurifier/AttrDef/CSS/FontTest.php index 6bcb4fe2..48650864 100644 --- a/tests/HTMLPurifier/AttrDef/CSS/FontTest.php +++ b/tests/HTMLPurifier/AttrDef/CSS/FontTest.php @@ -34,4 +34,3 @@ class HTMLPurifier_AttrDef_CSS_FontTest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/CSS/LengthTest.php b/tests/HTMLPurifier/AttrDef/CSS/LengthTest.php index 56129af2..d7914e80 100644 --- a/tests/HTMLPurifier/AttrDef/CSS/LengthTest.php +++ b/tests/HTMLPurifier/AttrDef/CSS/LengthTest.php @@ -40,4 +40,3 @@ class HTMLPurifier_AttrDef_CSS_LengthTest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/CSS/ListStyleTest.php b/tests/HTMLPurifier/AttrDef/CSS/ListStyleTest.php index 6863c489..ff9391a2 100644 --- a/tests/HTMLPurifier/AttrDef/CSS/ListStyleTest.php +++ b/tests/HTMLPurifier/AttrDef/CSS/ListStyleTest.php @@ -35,4 +35,3 @@ class HTMLPurifier_AttrDef_CSS_ListStyleTest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/CSS/MultipleTest.php b/tests/HTMLPurifier/AttrDef/CSS/MultipleTest.php index 075c56ad..81342a7c 100644 --- a/tests/HTMLPurifier/AttrDef/CSS/MultipleTest.php +++ b/tests/HTMLPurifier/AttrDef/CSS/MultipleTest.php @@ -30,4 +30,3 @@ class HTMLPurifier_AttrDef_CSS_MultipleTest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/CSS/NumberTest.php b/tests/HTMLPurifier/AttrDef/CSS/NumberTest.php index f8f714f6..071135be 100644 --- a/tests/HTMLPurifier/AttrDef/CSS/NumberTest.php +++ b/tests/HTMLPurifier/AttrDef/CSS/NumberTest.php @@ -37,4 +37,3 @@ class HTMLPurifier_AttrDef_CSS_NumberTest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/CSS/PercentageTest.php b/tests/HTMLPurifier/AttrDef/CSS/PercentageTest.php index 2aa0d401..3ca210a5 100644 --- a/tests/HTMLPurifier/AttrDef/CSS/PercentageTest.php +++ b/tests/HTMLPurifier/AttrDef/CSS/PercentageTest.php @@ -24,4 +24,3 @@ class HTMLPurifier_AttrDef_CSS_PercentageTest extends HTMLPurifier_AttrDefHarnes } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/CSS/TextDecorationTest.php b/tests/HTMLPurifier/AttrDef/CSS/TextDecorationTest.php index e5f3e0c7..fb0ccf4f 100644 --- a/tests/HTMLPurifier/AttrDef/CSS/TextDecorationTest.php +++ b/tests/HTMLPurifier/AttrDef/CSS/TextDecorationTest.php @@ -24,4 +24,3 @@ class HTMLPurifier_AttrDef_CSS_TextDecorationTest extends HTMLPurifier_AttrDefHa } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/CSS/URITest.php b/tests/HTMLPurifier/AttrDef/CSS/URITest.php index 2a238d22..97e547c8 100644 --- a/tests/HTMLPurifier/AttrDef/CSS/URITest.php +++ b/tests/HTMLPurifier/AttrDef/CSS/URITest.php @@ -34,4 +34,3 @@ class HTMLPurifier_AttrDef_CSS_URITest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/CSSTest.php b/tests/HTMLPurifier/AttrDef/CSSTest.php index 9371f788..2d1b4c60 100644 --- a/tests/HTMLPurifier/AttrDef/CSSTest.php +++ b/tests/HTMLPurifier/AttrDef/CSSTest.php @@ -108,4 +108,3 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/EnumTest.php b/tests/HTMLPurifier/AttrDef/EnumTest.php index fe405d85..013b660d 100644 --- a/tests/HTMLPurifier/AttrDef/EnumTest.php +++ b/tests/HTMLPurifier/AttrDef/EnumTest.php @@ -37,4 +37,3 @@ class HTMLPurifier_AttrDef_EnumTest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/HTML/BoolTest.php b/tests/HTMLPurifier/AttrDef/HTML/BoolTest.php index 47a31fc3..87e8a8eb 100644 --- a/tests/HTMLPurifier/AttrDef/HTML/BoolTest.php +++ b/tests/HTMLPurifier/AttrDef/HTML/BoolTest.php @@ -22,4 +22,3 @@ class HTMLPurifier_AttrDef_HTML_BoolTest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/HTML/ColorTest.php b/tests/HTMLPurifier/AttrDef/HTML/ColorTest.php index 39bd80db..72f6c90f 100644 --- a/tests/HTMLPurifier/AttrDef/HTML/ColorTest.php +++ b/tests/HTMLPurifier/AttrDef/HTML/ColorTest.php @@ -20,4 +20,3 @@ class HTMLPurifier_AttrDef_HTML_ColorTest extends HTMLPurifier_AttrDefHarness } } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/HTML/FrameTargetTest.php b/tests/HTMLPurifier/AttrDef/HTML/FrameTargetTest.php index 1e28ea16..11353336 100644 --- a/tests/HTMLPurifier/AttrDef/HTML/FrameTargetTest.php +++ b/tests/HTMLPurifier/AttrDef/HTML/FrameTargetTest.php @@ -28,4 +28,3 @@ class HTMLPurifier_AttrDef_HTML_FrameTargetTest extends HTMLPurifier_AttrDefHarn } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/HTML/IDTest.php b/tests/HTMLPurifier/AttrDef/HTML/IDTest.php index add764fd..dda0db41 100644 --- a/tests/HTMLPurifier/AttrDef/HTML/IDTest.php +++ b/tests/HTMLPurifier/AttrDef/HTML/IDTest.php @@ -109,4 +109,3 @@ class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/HTML/LengthTest.php b/tests/HTMLPurifier/AttrDef/HTML/LengthTest.php index e5b89f22..8fba0476 100644 --- a/tests/HTMLPurifier/AttrDef/HTML/LengthTest.php +++ b/tests/HTMLPurifier/AttrDef/HTML/LengthTest.php @@ -32,4 +32,3 @@ class HTMLPurifier_AttrDef_HTML_LengthTest extends HTMLPurifier_AttrDef_HTML_Pix } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/HTML/LinkTypesTest.php b/tests/HTMLPurifier/AttrDef/HTML/LinkTypesTest.php index 0acfac03..a6643f74 100644 --- a/tests/HTMLPurifier/AttrDef/HTML/LinkTypesTest.php +++ b/tests/HTMLPurifier/AttrDef/HTML/LinkTypesTest.php @@ -21,4 +21,3 @@ class HTMLPurifier_AttrDef_HTML_LinkTypesTest extends HTMLPurifier_AttrDefHarnes } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/HTML/MultiLengthTest.php b/tests/HTMLPurifier/AttrDef/HTML/MultiLengthTest.php index eaa34952..7a305c30 100644 --- a/tests/HTMLPurifier/AttrDef/HTML/MultiLengthTest.php +++ b/tests/HTMLPurifier/AttrDef/HTML/MultiLengthTest.php @@ -28,4 +28,3 @@ class HTMLPurifier_AttrDef_HTML_MultiLengthTest extends HTMLPurifier_AttrDef_HTM } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/HTML/NmtokensTest.php b/tests/HTMLPurifier/AttrDef/HTML/NmtokensTest.php index 00b55eec..3d218061 100644 --- a/tests/HTMLPurifier/AttrDef/HTML/NmtokensTest.php +++ b/tests/HTMLPurifier/AttrDef/HTML/NmtokensTest.php @@ -32,4 +32,3 @@ class HTMLPurifier_AttrDef_HTML_NmtokensTest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/HTML/PixelsTest.php b/tests/HTMLPurifier/AttrDef/HTML/PixelsTest.php index 414fa3ad..6fa899bf 100644 --- a/tests/HTMLPurifier/AttrDef/HTML/PixelsTest.php +++ b/tests/HTMLPurifier/AttrDef/HTML/PixelsTest.php @@ -38,4 +38,3 @@ class HTMLPurifier_AttrDef_HTML_PixelsTest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/IntegerTest.php b/tests/HTMLPurifier/AttrDef/IntegerTest.php index 98cefbac..43714d8e 100644 --- a/tests/HTMLPurifier/AttrDef/IntegerTest.php +++ b/tests/HTMLPurifier/AttrDef/IntegerTest.php @@ -61,4 +61,3 @@ class HTMLPurifier_AttrDef_IntegerTest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/LangTest.php b/tests/HTMLPurifier/AttrDef/LangTest.php index a5472e91..cafa5db2 100644 --- a/tests/HTMLPurifier/AttrDef/LangTest.php +++ b/tests/HTMLPurifier/AttrDef/LangTest.php @@ -85,4 +85,3 @@ class HTMLPurifier_AttrDef_LangTest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/TextTest.php b/tests/HTMLPurifier/AttrDef/TextTest.php index 2aa4128d..4977edcd 100644 --- a/tests/HTMLPurifier/AttrDef/TextTest.php +++ b/tests/HTMLPurifier/AttrDef/TextTest.php @@ -17,4 +17,3 @@ class HTMLPurifier_AttrDef_TextTest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/URI/Email/SimpleCheckTest.php b/tests/HTMLPurifier/AttrDef/URI/Email/SimpleCheckTest.php index edbde119..6b8cae31 100644 --- a/tests/HTMLPurifier/AttrDef/URI/Email/SimpleCheckTest.php +++ b/tests/HTMLPurifier/AttrDef/URI/Email/SimpleCheckTest.php @@ -13,4 +13,3 @@ class HTMLPurifier_AttrDef_URI_Email_SimpleCheckTest } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/URI/EmailHarness.php b/tests/HTMLPurifier/AttrDef/URI/EmailHarness.php index b0398424..3c14e4eb 100644 --- a/tests/HTMLPurifier/AttrDef/URI/EmailHarness.php +++ b/tests/HTMLPurifier/AttrDef/URI/EmailHarness.php @@ -31,4 +31,3 @@ class HTMLPurifier_AttrDef_URI_EmailHarness extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/URI/HostTest.php b/tests/HTMLPurifier/AttrDef/URI/HostTest.php index d3e44753..33424eca 100644 --- a/tests/HTMLPurifier/AttrDef/URI/HostTest.php +++ b/tests/HTMLPurifier/AttrDef/URI/HostTest.php @@ -21,4 +21,3 @@ class HTMLPurifier_AttrDef_URI_HostTest extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/URI/IPv6Test.php b/tests/HTMLPurifier/AttrDef/URI/IPv6Test.php index 8a6511b0..33b56ad4 100644 --- a/tests/HTMLPurifier/AttrDef/URI/IPv6Test.php +++ b/tests/HTMLPurifier/AttrDef/URI/IPv6Test.php @@ -43,4 +43,3 @@ class HTMLPurifier_AttrDef_URI_IPv6Test extends HTMLPurifier_AttrDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/URITest.php b/tests/HTMLPurifier/AttrDef/URITest.php index e6aab057..a4d2521e 100644 --- a/tests/HTMLPurifier/AttrDef/URITest.php +++ b/tests/HTMLPurifier/AttrDef/URITest.php @@ -202,11 +202,11 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness // $fake_registry isn't the real mock, because due to PHP 4 weirdness // I cannot set a default value to function parameters that are passed // by reference. So we use the value instance() returns. - $fake_registry = new HTMLPurifier_URISchemeRegistryMock($this); + $fake_registry = new HTMLPurifier_URISchemeRegistryMock(); $registry =& HTMLPurifier_URISchemeRegistry::instance($fake_registry); // now, let's add a pseudo-scheme to the registry - $this->scheme = new HTMLPurifier_URISchemeMock($this); + $this->scheme = new HTMLPurifier_URISchemeMock(); // here are the schemes we will support with overloaded mocks $registry->setReturnReference('getScheme', $this->scheme, array('http', '*', '*')); @@ -325,4 +325,4 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness } -?> + diff --git a/tests/HTMLPurifier/AttrDefHarness.php b/tests/HTMLPurifier/AttrDefHarness.php index e6c6359e..84d8cc9e 100644 --- a/tests/HTMLPurifier/AttrDefHarness.php +++ b/tests/HTMLPurifier/AttrDefHarness.php @@ -30,4 +30,3 @@ class HTMLPurifier_AttrDefHarness extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDefTest.php b/tests/HTMLPurifier/AttrDefTest.php index a8963bc4..0cd11310 100644 --- a/tests/HTMLPurifier/AttrDefTest.php +++ b/tests/HTMLPurifier/AttrDefTest.php @@ -27,4 +27,3 @@ class HTMLPurifier_AttrDefTest extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrTransform/BdoDirTest.php b/tests/HTMLPurifier/AttrTransform/BdoDirTest.php index 93b051dc..d1ef2468 100644 --- a/tests/HTMLPurifier/AttrTransform/BdoDirTest.php +++ b/tests/HTMLPurifier/AttrTransform/BdoDirTest.php @@ -29,4 +29,3 @@ class HTMLPurifier_AttrTransform_BdoDirTest extends HTMLPurifier_AttrTransformHa } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrTransform/BgColorTest.php b/tests/HTMLPurifier/AttrTransform/BgColorTest.php index 6ad35bde..69429ad8 100644 --- a/tests/HTMLPurifier/AttrTransform/BgColorTest.php +++ b/tests/HTMLPurifier/AttrTransform/BgColorTest.php @@ -40,4 +40,3 @@ class HTMLPurifier_AttrTransform_BgColorTest extends HTMLPurifier_AttrTransformH } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrTransform/BoolToCSSTest.php b/tests/HTMLPurifier/AttrTransform/BoolToCSSTest.php index b6794600..70b4fbdb 100644 --- a/tests/HTMLPurifier/AttrTransform/BoolToCSSTest.php +++ b/tests/HTMLPurifier/AttrTransform/BoolToCSSTest.php @@ -36,4 +36,3 @@ class HTMLPurifier_AttrTransform_BoolToCSSTest extends HTMLPurifier_AttrTransfor } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrTransform/BorderTest.php b/tests/HTMLPurifier/AttrTransform/BorderTest.php index a592e41b..25fb3c66 100644 --- a/tests/HTMLPurifier/AttrTransform/BorderTest.php +++ b/tests/HTMLPurifier/AttrTransform/BorderTest.php @@ -37,4 +37,3 @@ class HTMLPurifier_AttrTransform_BorderTest extends HTMLPurifier_AttrTransformHa } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrTransform/EnumToCSSTest.php b/tests/HTMLPurifier/AttrTransform/EnumToCSSTest.php index 565cee45..38bc0f14 100644 --- a/tests/HTMLPurifier/AttrTransform/EnumToCSSTest.php +++ b/tests/HTMLPurifier/AttrTransform/EnumToCSSTest.php @@ -75,4 +75,3 @@ class HTMLPurifier_AttrTransform_EnumToCSSTest extends HTMLPurifier_AttrTransfor } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrTransform/ImgRequiredTest.php b/tests/HTMLPurifier/AttrTransform/ImgRequiredTest.php index a9ad9a8c..b1d871b4 100644 --- a/tests/HTMLPurifier/AttrTransform/ImgRequiredTest.php +++ b/tests/HTMLPurifier/AttrTransform/ImgRequiredTest.php @@ -48,4 +48,3 @@ class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransf } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrTransform/ImgSpaceTest.php b/tests/HTMLPurifier/AttrTransform/ImgSpaceTest.php index 8426f15c..8fc9178f 100644 --- a/tests/HTMLPurifier/AttrTransform/ImgSpaceTest.php +++ b/tests/HTMLPurifier/AttrTransform/ImgSpaceTest.php @@ -54,4 +54,3 @@ class HTMLPurifier_AttrTransform_ImgSpaceTest extends HTMLPurifier_AttrTransform } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrTransform/LangTest.php b/tests/HTMLPurifier/AttrTransform/LangTest.php index 2e3551b3..42232ca3 100644 --- a/tests/HTMLPurifier/AttrTransform/LangTest.php +++ b/tests/HTMLPurifier/AttrTransform/LangTest.php @@ -46,4 +46,3 @@ class HTMLPurifier_AttrTransform_LangTest } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrTransform/LengthTest.php b/tests/HTMLPurifier/AttrTransform/LengthTest.php index e0c9474b..62068e4b 100644 --- a/tests/HTMLPurifier/AttrTransform/LengthTest.php +++ b/tests/HTMLPurifier/AttrTransform/LengthTest.php @@ -34,4 +34,3 @@ class HTMLPurifier_AttrTransform_LengthTest extends HTMLPurifier_AttrTransformHa } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrTransform/NameTest.php b/tests/HTMLPurifier/AttrTransform/NameTest.php index da4498fb..30e9e58b 100644 --- a/tests/HTMLPurifier/AttrTransform/NameTest.php +++ b/tests/HTMLPurifier/AttrTransform/NameTest.php @@ -25,4 +25,3 @@ class HTMLPurifier_AttrTransform_NameTest extends HTMLPurifier_AttrTransformHarn } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrTransformHarness.php b/tests/HTMLPurifier/AttrTransformHarness.php index aff1d6b7..1f7839d0 100644 --- a/tests/HTMLPurifier/AttrTransformHarness.php +++ b/tests/HTMLPurifier/AttrTransformHarness.php @@ -11,4 +11,3 @@ class HTMLPurifier_AttrTransformHarness extends HTMLPurifier_Harness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrTransformTest.php b/tests/HTMLPurifier/AttrTransformTest.php index fac01633..e75352fb 100644 --- a/tests/HTMLPurifier/AttrTransformTest.php +++ b/tests/HTMLPurifier/AttrTransformTest.php @@ -39,4 +39,3 @@ class HTMLPurifier_AttrTransformTest extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrTypesTest.php b/tests/HTMLPurifier/AttrTypesTest.php index 9d919a83..3f09dd1f 100644 --- a/tests/HTMLPurifier/AttrTypesTest.php +++ b/tests/HTMLPurifier/AttrTypesTest.php @@ -25,4 +25,3 @@ class HTMLPurifier_AttrTypesTest extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrValidator_ErrorsTest.php b/tests/HTMLPurifier/AttrValidator_ErrorsTest.php new file mode 100644 index 00000000..08f59c99 --- /dev/null +++ b/tests/HTMLPurifier/AttrValidator_ErrorsTest.php @@ -0,0 +1,49 @@ +validateToken($input, $this->config, $this->context); + } + + function testAttributesTransformedGlobalPre() { + $this->config->set('HTML', 'DefinitionID', + 'HTMLPurifier_AttrValidator_ErrorsTest::testAttributesTransformedGlobalPre'); + $def =& $this->config->getHTMLDefinition(true); + generate_mock_once('HTMLPurifier_AttrTransform'); + $transform = new HTMLPurifier_AttrTransformMock(); + $input = array('original' => 'value'); + $output = array('class' => 'value'); // must be valid + $transform->setReturnValue('transform', $output, array($input, new AnythingExpectation(), new AnythingExpectation())); + $def->info_attr_transform_pre[] = $transform; + $this->expectErrorCollection(E_NOTICE, 'AttrValidator: Attributes transformed', $input, $output); + $token = new HTMLPurifier_Token_Start('span', $input, 1); + $this->invoke($token); + } + + function testAttributesTransformedLocalPre() { + $this->config->set('HTML', 'TidyLevel', 'heavy'); + $input = array('align' => 'right'); + $output = array('style' => 'text-align:right;'); + $this->expectErrorCollection(E_NOTICE, 'AttrValidator: Attributes transformed', $input, $output); + $token = new HTMLPurifier_Token_Start('p', $input, 1); + $this->invoke($token); + } + + // to lazy to check for global post and global pre + + function testAttributeRemoved() { + $this->expectErrorCollection(E_ERROR, 'AttrValidator: Attribute removed'); + $this->expectContext('CurrentAttr', 'foobar'); + $token = new HTMLPurifier_Token_Start('p', array('foobar' => 'right'), 1); + $this->expectContext('CurrentToken', $token); + $this->invoke($token); + } + +} + diff --git a/tests/HTMLPurifier/ChildDef/ChameleonTest.php b/tests/HTMLPurifier/ChildDef/ChameleonTest.php index 529d9193..676bbe48 100644 --- a/tests/HTMLPurifier/ChildDef/ChameleonTest.php +++ b/tests/HTMLPurifier/ChildDef/ChameleonTest.php @@ -32,4 +32,3 @@ class HTMLPurifier_ChildDef_ChameleonTest extends HTMLPurifier_ChildDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/ChildDef/CustomTest.php b/tests/HTMLPurifier/ChildDef/CustomTest.php index e4f00a62..2b33f7cf 100644 --- a/tests/HTMLPurifier/ChildDef/CustomTest.php +++ b/tests/HTMLPurifier/ChildDef/CustomTest.php @@ -10,6 +10,9 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness $this->obj = new HTMLPurifier_ChildDef_Custom('(a,b?,c*,d+,(a,b)*)'); + $this->assertEqual($this->obj->elements, array('a' => true, + 'b' => true, 'c' => true, 'd' => true)); + $this->assertResult('', false); $this->assertResult('', false); @@ -21,6 +24,8 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness function testNesting() { $this->obj = new HTMLPurifier_ChildDef_Custom('(a,b,(c|d))+'); + $this->assertEqual($this->obj->elements, array('a' => true, + 'b' => true, 'c' => true, 'd' => true)); $this->assertResult('', false); $this->assertResult(''); $this->assertResult('', false); @@ -28,6 +33,8 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness function testNestedEitherOr() { $this->obj = new HTMLPurifier_ChildDef_Custom('b,(a|(c|d))+'); + $this->assertEqual($this->obj->elements, array('a' => true, + 'b' => true, 'c' => true, 'd' => true)); $this->assertResult('', false); $this->assertResult(''); $this->assertResult(''); @@ -37,6 +44,7 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness function testNestedQuantifier() { $this->obj = new HTMLPurifier_ChildDef_Custom('(b,c+)*'); + $this->assertEqual($this->obj->elements, array('b' => true, 'c' => true)); $this->assertResult(''); $this->assertResult(''); $this->assertResult(''); @@ -47,6 +55,7 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness function testEitherOr() { $this->obj = new HTMLPurifier_ChildDef_Custom('a|b'); + $this->assertEqual($this->obj->elements, array('a' => true, 'b' => true)); $this->assertResult('', false); $this->assertResult(''); $this->assertResult(''); @@ -57,6 +66,7 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness function testCommafication() { $this->obj = new HTMLPurifier_ChildDef_Custom('a,b'); + $this->assertEqual($this->obj->elements, array('a' => true, 'b' => true)); $this->assertResult(''); $this->assertResult('', false); @@ -64,4 +74,3 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/ChildDef/OptionalTest.php b/tests/HTMLPurifier/ChildDef/OptionalTest.php index 4e44e8b7..bdb5ac05 100644 --- a/tests/HTMLPurifier/ChildDef/OptionalTest.php +++ b/tests/HTMLPurifier/ChildDef/OptionalTest.php @@ -17,4 +17,3 @@ class HTMLPurifier_ChildDef_OptionalTest extends HTMLPurifier_ChildDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/ChildDef/RequiredTest.php b/tests/HTMLPurifier/ChildDef/RequiredTest.php index 0e8c8b1e..e708abea 100644 --- a/tests/HTMLPurifier/ChildDef/RequiredTest.php +++ b/tests/HTMLPurifier/ChildDef/RequiredTest.php @@ -66,4 +66,3 @@ class HTMLPurifier_ChildDef_RequiredTest extends HTMLPurifier_ChildDefHarness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/ChildDef/StrictBlockquoteTest.php b/tests/HTMLPurifier/ChildDef/StrictBlockquoteTest.php index 76113bcd..dd00bfa8 100644 --- a/tests/HTMLPurifier/ChildDef/StrictBlockquoteTest.php +++ b/tests/HTMLPurifier/ChildDef/StrictBlockquoteTest.php @@ -42,12 +42,14 @@ extends HTMLPurifier_ChildDefHarness $this->assertResult('Needs wrap', '
Needs wrap
', array('HTML.BlockWrapper' => 'div')); - $this->expectError('Cannot use non-block element as block wrapper.'); + } + + function testError() { + $this->obj = new HTMLPurifier_ChildDef_StrictBlockquote('div | p'); $this->assertResult('Needs wrap', '

Needs wrap

', array('HTML.BlockWrapper' => 'dav')); - + $this->swallowErrors(); } } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/ChildDef/TableTest.php b/tests/HTMLPurifier/ChildDef/TableTest.php index d5780a63..466ca6ee 100644 --- a/tests/HTMLPurifier/ChildDef/TableTest.php +++ b/tests/HTMLPurifier/ChildDef/TableTest.php @@ -38,14 +38,14 @@ class HTMLPurifier_ChildDef_TableTest extends HTMLPurifier_ChildDefHarness // whitespace sticks to the previous element, last whitespace is // stationary - $this->assertResult("\n \n \n "); + $this->assertResult("\n \n \n ", true, array('Output.Newline' => "\n")); $this->assertResult( "\n\t\n\t\t\n\t\t\t", - "\n\t\t\n\t\n\t\t\t" + "\n\t\t\n\t\n\t\t\t", + array('Output.Newline' => "\n") ); } } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/ChildDefHarness.php b/tests/HTMLPurifier/ChildDefHarness.php index 37c3f406..1ea04089 100644 --- a/tests/HTMLPurifier/ChildDefHarness.php +++ b/tests/HTMLPurifier/ChildDefHarness.php @@ -15,4 +15,4 @@ class HTMLPurifier_ChildDefHarness extends HTMLPurifier_Harness } -?> + diff --git a/tests/HTMLPurifier/ConfigSchemaTest.php b/tests/HTMLPurifier/ConfigSchemaTest.php index c743606f..8dfb8f4c 100644 --- a/tests/HTMLPurifier/ConfigSchemaTest.php +++ b/tests/HTMLPurifier/ConfigSchemaTest.php @@ -336,4 +336,3 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/ConfigTest.php b/tests/HTMLPurifier/ConfigTest.php index 5387a3c4..a2dff2d2 100644 --- a/tests/HTMLPurifier/ConfigTest.php +++ b/tests/HTMLPurifier/ConfigTest.php @@ -252,9 +252,10 @@ class HTMLPurifier_ConfigTest extends UnitTestCase // test retrieval of raw definition $config->set('HTML', 'DefinitionID', 'HTMLPurifier_ConfigTest->test_getHTMLDefinition()'); + $config->set('HTML', 'DefinitionRev', 3); $def =& $config->getHTMLDefinition(true); $this->assertNotEqual($def, $def2); - $this->assertFalse($def->setup); + $this->assertEqual(false, $def->setup); // auto initialization $config->getHTMLDefinition(); @@ -277,8 +278,8 @@ class HTMLPurifier_ConfigTest extends UnitTestCase } function test_getDefinition() { - CS::defineNamespace('Core', 'Core stuff'); - CS::define('Core', 'DefinitionCache', null, 'string/null', 'Cache?'); + CS::defineNamespace('Cache', 'Cache stuff'); + CS::define('Cache', 'DefinitionImpl', null, 'string/null', 'Cache?'); CS::defineNamespace('Crust', 'Krusty Krabs'); $config = HTMLPurifier_Config::createDefault(); $this->expectError("Definition of Crust type not supported"); @@ -375,6 +376,85 @@ class HTMLPurifier_ConfigTest extends UnitTestCase } + function test_loadArrayFromForm() { + + CS::defineNamespace('Pancake', 'This should not be user customizable'); + CS::define('Pancake', 'Mix', 'buttermilk', 'string', 'Type of pancake mix to use.'); + CS::define('Pancake', 'Served', true, 'bool', 'But this is customizable by user.'); + CS::defineNamespace('Toppings', 'This is user customizable'); + CS::define('Toppings', 'Syrup', true, 'bool', 'Absolutely standard!'); + CS::define('Toppings', 'Flavor', 'maple', 'string', 'What flavor is the syrup?'); + CS::define('Toppings', 'Strawberries', 3, 'int', 'Quite delightful fruit.'); + CS::define('Toppings', 'Calories', 2000, 'int/null', 'Some things are best left unknown.'); + CS::define('Toppings', 'DefinitionID', null, 'string/null', 'Do not let this be set'); + CS::define('Toppings', 'DefinitionRev', 1, 'int', 'Do not let this be set'); + CS::define('Toppings', 'Protected', 1, 'int', 'Do not let this be set'); + + $get = array( + 'breakfast' => array( + 'Pancake.Mix' => 'nasty', + 'Pancake.Served' => '0', + 'Toppings.Syrup' => '0', + 'Toppings.Flavor' => "juice", + 'Toppings.Strawberries' => '999', + 'Toppings.Calories' => '', + 'Null_Toppings.Calories' => '1', + 'Toppings.DefinitionID' => '', + 'Toppings.DefinitionRev' => '65', + 'Toppings.Protected' => '4', + ) + ); + + $config_expect = HTMLPurifier_Config::create(array( + 'Pancake.Served' => false, + 'Toppings.Syrup' => false, + 'Toppings.Flavor' => "juice", + 'Toppings.Strawberries' => 999, + 'Toppings.Calories' => null + )); + + $config_result = HTMLPurifier_Config::loadArrayFromForm($get, 'breakfast', array('Pancake.Served', 'Toppings', '-Toppings.Protected')); + + $this->assertEqual($config_expect, $config_result); + + /* + MAGIC QUOTES NOT TESTED!!! + + $get = array( + 'breakfast' => array( + 'Pancake.Mix' => 'n\\asty' + ) + ); + $config_expect = HTMLPurifier_Config::create(array( + 'Pancake.Mix' => 'n\\asty' + )); + $config_result = HTMLPurifier_Config::loadArrayFromForm($get, 'breakfast', true, false); + $this->assertEqual($config_expect, $config_result); + */ + } + + function test_getAllowedDirectivesForForm() { + CS::defineNamespace('Unused', 'Not mentioned, so deny'); + CS::define('Unused', 'Unused', 'Foobar', 'string', 'Not mentioned, do not allow'); + CS::defineNamespace('Partial', 'Some are mentioned, allow only those'); + CS::define('Partial', 'Allowed', true, 'bool', 'Mentioned, allowed'); + CS::define('Partial', 'Unused', 'Foobar', 'string', 'Not mentioned, do not allow'); + CS::defineNamespace('All', 'Entire namespace allowed, allow all unless...'); + CS::define('All', 'Allowed', true, 'bool', 'Not mentioned, allowed'); + CS::define('All', 'Blacklisted', 'Foobar', 'string', 'Specifically blacklisted'); + CS::define('All', 'DefinitionID', 'Foobar', 'string/null', 'Special case, auto-blacklisted'); + CS::define('All', 'DefinitionRev', 2, 'int', 'Special case, auto-blacklisted'); + + $input = array('Partial.Allowed', 'All', '-All.Blacklisted'); + $output = HTMLPurifier_Config::getAllowedDirectivesForForm($input); + $expect = array( + array('Partial', 'Allowed'), + array('All', 'Allowed') + ); + + $this->assertEqual($output, $expect); + + } + } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/ContextTest.php b/tests/HTMLPurifier/ContextTest.php index 195a5030..8e038159 100644 --- a/tests/HTMLPurifier/ContextTest.php +++ b/tests/HTMLPurifier/ContextTest.php @@ -20,7 +20,7 @@ class HTMLPurifier_ContextTest extends UnitTestCase $this->assertFalse($this->context->exists('IDAccumulator')); - $accumulator = new HTMLPurifier_IDAccumulatorMock($this); + $accumulator = new HTMLPurifier_IDAccumulatorMock(); $this->context->register('IDAccumulator', $accumulator); $this->assertTrue($this->context->exists('IDAccumulator')); @@ -30,11 +30,11 @@ class HTMLPurifier_ContextTest extends UnitTestCase $this->context->destroy('IDAccumulator'); $this->assertFalse($this->context->exists('IDAccumulator')); - $this->expectError('Attempted to retrieve non-existent variable'); + $this->expectError('Attempted to retrieve non-existent variable IDAccumulator'); $accumulator_3 =& $this->context->get('IDAccumulator'); $this->assertNull($accumulator_3); - $this->expectError('Attempted to destroy non-existent variable'); + $this->expectError('Attempted to destroy non-existent variable IDAccumulator'); $this->context->destroy('IDAccumulator'); } @@ -44,7 +44,7 @@ class HTMLPurifier_ContextTest extends UnitTestCase $var = true; $this->context->register('OnceOnly', $var); - $this->expectError('Name collision, cannot re-register'); + $this->expectError('Name OnceOnly produces collision, cannot re-register'); $this->context->register('OnceOnly', $var); // destroy it, now registration is okay @@ -85,4 +85,3 @@ class HTMLPurifier_ContextTest extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/DefinitionCache/Decorator/CleanupTest.php b/tests/HTMLPurifier/DefinitionCache/Decorator/CleanupTest.php index 758a4cb8..dc60752a 100644 --- a/tests/HTMLPurifier/DefinitionCache/Decorator/CleanupTest.php +++ b/tests/HTMLPurifier/DefinitionCache/Decorator/CleanupTest.php @@ -56,4 +56,3 @@ class HTMLPurifier_DefinitionCache_Decorator_CleanupTest extends HTMLPurifier_De } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/DefinitionCache/Decorator/MemoryTest.php b/tests/HTMLPurifier/DefinitionCache/Decorator/MemoryTest.php index b7f89c56..cba780fb 100644 --- a/tests/HTMLPurifier/DefinitionCache/Decorator/MemoryTest.php +++ b/tests/HTMLPurifier/DefinitionCache/Decorator/MemoryTest.php @@ -70,4 +70,3 @@ class HTMLPurifier_DefinitionCache_Decorator_MemoryTest extends HTMLPurifier_Def } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/DefinitionCache/DecoratorHarness.php b/tests/HTMLPurifier/DefinitionCache/DecoratorHarness.php index c5c75635..78c753a3 100644 --- a/tests/HTMLPurifier/DefinitionCache/DecoratorHarness.php +++ b/tests/HTMLPurifier/DefinitionCache/DecoratorHarness.php @@ -9,7 +9,7 @@ class HTMLPurifier_DefinitionCache_DecoratorHarness extends HTMLPurifier_Definit { function setup() { - $this->mock = new HTMLPurifier_DefinitionCacheMock($this); + $this->mock = new HTMLPurifier_DefinitionCacheMock(); $this->mock->type = 'Test'; $this->cache = $this->cache->decorate($this->mock); $this->def = $this->generateDefinition(); @@ -23,4 +23,3 @@ class HTMLPurifier_DefinitionCache_DecoratorHarness extends HTMLPurifier_Definit } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/DefinitionCache/DecoratorTest.php b/tests/HTMLPurifier/DefinitionCache/DecoratorTest.php index 49b1c68d..1390d543 100644 --- a/tests/HTMLPurifier/DefinitionCache/DecoratorTest.php +++ b/tests/HTMLPurifier/DefinitionCache/DecoratorTest.php @@ -9,7 +9,7 @@ class HTMLPurifier_DefinitionCache_DecoratorTest extends HTMLPurifier_Definition function test() { generate_mock_once('HTMLPurifier_DefinitionCache'); - $mock = new HTMLPurifier_DefinitionCacheMock($this); + $mock = new HTMLPurifier_DefinitionCacheMock(); $mock->type = 'Test'; $cache = new HTMLPurifier_DefinitionCache_Decorator(); @@ -42,4 +42,3 @@ class HTMLPurifier_DefinitionCache_DecoratorTest extends HTMLPurifier_Definition } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/DefinitionCache/SerializerTest.php b/tests/HTMLPurifier/DefinitionCache/SerializerTest.php index 99867b03..4925ff8e 100644 --- a/tests/HTMLPurifier/DefinitionCache/SerializerTest.php +++ b/tests/HTMLPurifier/DefinitionCache/SerializerTest.php @@ -14,7 +14,7 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio $config->setReturnValue('get', 2, array('Test', 'DefinitionRev')); $config->version = '1.0.0'; - $config_md5 = '1.0.0-2-serial'; + $config_md5 = '1.0.0-serial-2'; $file = realpath( $rel_file = dirname(__FILE__) . @@ -138,6 +138,32 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio } + function testCleanupOnlySameID() { + + $cache = new HTMLPurifier_DefinitionCache_Serializer('Test'); + + $config1 = $this->generateConfigMock('serial1'); + $config1->version = '1.0.0'; + $config1->setReturnValue('get', 1, array('Test', 'DefinitionRev')); + $def1 = $this->generateDefinition(array('info' => 1)); + + $config2 = $this->generateConfigMock('serial2'); + $config2->version = '1.0.0'; + $config2->setReturnValue('get', 34, array('Test', 'DefinitionRev')); + $def2 = $this->generateDefinition(array('info' => 3)); + + $cache->set($def1, $config1); + $cache->cleanup($config1); + $this->assertEqual($def1, $cache->get($config1)); // no change + + $cache->set($def2, $config2); + $cache->cleanup($config2); + $this->assertEqual($def1, $cache->get($config1)); + $this->assertEqual($def2, $cache->get($config2)); + + $cache->flush($config1); + } + /** * Asserts that a file exists, ignoring the stat cache */ @@ -164,13 +190,12 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio $def_original = $this->generateDefinition(); $cache->add($def_original, $config); - $this->assertFileExist($dir . '/Test/1.0.0-1-serial.ser'); + $this->assertFileExist($dir . '/Test/1.0.0-serial-1.ser'); - unlink($dir . '/Test/1.0.0-1-serial.ser'); + unlink($dir . '/Test/1.0.0-serial-1.ser'); rmdir( $dir . '/Test'); } } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/DefinitionCacheFactoryTest.php b/tests/HTMLPurifier/DefinitionCacheFactoryTest.php index 892f8805..beabc33c 100644 --- a/tests/HTMLPurifier/DefinitionCacheFactoryTest.php +++ b/tests/HTMLPurifier/DefinitionCacheFactoryTest.php @@ -62,4 +62,3 @@ class HTMLPurifier_DefinitionCacheFactoryTest extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/DefinitionCacheHarness.php b/tests/HTMLPurifier/DefinitionCacheHarness.php index efcb49a4..7304ecdd 100644 --- a/tests/HTMLPurifier/DefinitionCacheHarness.php +++ b/tests/HTMLPurifier/DefinitionCacheHarness.php @@ -10,7 +10,7 @@ class HTMLPurifier_DefinitionCacheHarness extends UnitTestCase */ function generateConfigMock($serial = 'defaultserial') { generate_mock_once('HTMLPurifier_Config'); - $config = new HTMLPurifier_ConfigMock($this); + $config = new HTMLPurifier_ConfigMock(); $config->setReturnValue('getBatchSerial', $serial, array('Test')); $config->version = '1.0.0'; return $config; @@ -31,4 +31,3 @@ class HTMLPurifier_DefinitionCacheHarness extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/DefinitionCacheTest.php b/tests/HTMLPurifier/DefinitionCacheTest.php index 702712ff..eef49f14 100644 --- a/tests/HTMLPurifier/DefinitionCacheTest.php +++ b/tests/HTMLPurifier/DefinitionCacheTest.php @@ -15,16 +15,22 @@ class HTMLPurifier_DefinitionCacheTest extends UnitTestCase HTMLPurifier_ConfigSchema::defineNamespace('Test', 'Test namespace'); HTMLPurifier_ConfigSchema::define('Test', 'DefinitionRev', 1, 'int', 'Definition revision.'); - $config = HTMLPurifier_Config::createDefault(); - $config->version = '1.0.0'; - $config->set('Test', 'DefinitionRev', 10); + generate_mock_once('HTMLPurifier_Config'); + $config = new HTMLPurifier_ConfigMock(); + $config->version = '1.0.0'; // hopefully no conflicts + $config->setReturnValue('get', 10, array('Test', 'DefinitionRev')); + $config->setReturnValue('getBatchSerial', 'hash', array('Test')); - $this->assertIdentical($cache->isOld('1.0.0-10-hashstuffhere', $config), false); - $this->assertIdentical($cache->isOld('1.5.0-1-hashstuffhere', $config), false); + $this->assertIdentical($cache->isOld('1.0.0-hash-10', $config), false); + $this->assertIdentical($cache->isOld('1.5.0-hash-1', $config), true); - $this->assertIdentical($cache->isOld('0.9.0-1-hashstuffhere', $config), true); - $this->assertIdentical($cache->isOld('1.0.0-1-hashstuffhere', $config), true); - $this->assertIdentical($cache->isOld('1.0.0beta-11-hashstuffhere', $config), true); + $this->assertIdentical($cache->isOld('0.9.0-hash-1', $config), true); + $this->assertIdentical($cache->isOld('1.0.0-hash-1', $config), true); + $this->assertIdentical($cache->isOld('1.0.0beta-hash-11', $config), true); + + $this->assertIdentical($cache->isOld('0.9.0-hash2-1', $config), true); + $this->assertIdentical($cache->isOld('1.0.0-hash2-1', $config), false); // if hash is different, don't touch! + $this->assertIdentical($cache->isOld('1.0.0beta-hash2-11', $config), true); HTMLPurifier_ConfigSchema::instance($old_copy); @@ -32,4 +38,3 @@ class HTMLPurifier_DefinitionCacheTest extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/DefinitionTest.php b/tests/HTMLPurifier/DefinitionTest.php index 2ce85d07..250e0845 100644 --- a/tests/HTMLPurifier/DefinitionTest.php +++ b/tests/HTMLPurifier/DefinitionTest.php @@ -30,4 +30,3 @@ class HTMLPurifier_DefinitionTest extends UnitTestCase } } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/DoctypeRegistryTest.php b/tests/HTMLPurifier/DoctypeRegistryTest.php index 385859c9..23375411 100644 --- a/tests/HTMLPurifier/DoctypeRegistryTest.php +++ b/tests/HTMLPurifier/DoctypeRegistryTest.php @@ -76,4 +76,3 @@ class HTMLPurifier_DoctypeRegistryTest extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/ElementDefTest.php b/tests/HTMLPurifier/ElementDefTest.php index 23ef6e17..04b4b0af 100644 --- a/tests/HTMLPurifier/ElementDefTest.php +++ b/tests/HTMLPurifier/ElementDefTest.php @@ -33,10 +33,6 @@ class HTMLPurifier_ElementDefTest extends UnitTestCase $def1->child = $overloaded_old; $def1->content_model = 'old'; $def1->content_model_type = $overloaded_old; - $def1->auto_close = array( - 'old' => true, - 'removed-old' => true - ); $def1->descendants_are_inline = false; $def1->excludes = array( 'old' => true, @@ -60,10 +56,6 @@ class HTMLPurifier_ElementDefTest extends UnitTestCase $def2->child = $new; $def2->content_model = 'new'; $def2->content_model_type = $overloaded_new; - $def2->auto_close = array( - 'new' => true, - 'removed-old' => false - ); $def2->descendants_are_inline = true; $def2->excludes = array( 'new' => true, @@ -90,10 +82,6 @@ class HTMLPurifier_ElementDefTest extends UnitTestCase $this->assertIdentical($def1->child, $new); $this->assertIdentical($def1->content_model, 'old | new'); $this->assertIdentical($def1->content_model_type, $overloaded_new); - $this->assertIdentical($def1->auto_close, array( - 'old' => true, - 'new' => true - )); $this->assertIdentical($def1->descendants_are_inline, true); $this->assertIdentical($def1->excludes, array( 'old' => true, @@ -105,4 +93,3 @@ class HTMLPurifier_ElementDefTest extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/EncoderTest.php b/tests/HTMLPurifier/EncoderTest.php index 0bab873e..5cf6a240 100644 --- a/tests/HTMLPurifier/EncoderTest.php +++ b/tests/HTMLPurifier/EncoderTest.php @@ -141,4 +141,3 @@ class HTMLPurifier_EncoderTest extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/EntityLookupTest.php b/tests/HTMLPurifier/EntityLookupTest.php index c490d55a..706b7c18 100644 --- a/tests/HTMLPurifier/EntityLookupTest.php +++ b/tests/HTMLPurifier/EntityLookupTest.php @@ -26,4 +26,3 @@ class HTMLPurifier_EntityLookupTest extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/EntityParserTest.php b/tests/HTMLPurifier/EntityParserTest.php index 54328d34..2d3a4d29 100644 --- a/tests/HTMLPurifier/EntityParserTest.php +++ b/tests/HTMLPurifier/EntityParserTest.php @@ -82,4 +82,3 @@ class HTMLPurifier_EntityParserTest extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/ErrorCollectorEMock.php b/tests/HTMLPurifier/ErrorCollectorEMock.php new file mode 100644 index 00000000..c0f577d5 --- /dev/null +++ b/tests/HTMLPurifier/ErrorCollectorEMock.php @@ -0,0 +1,46 @@ +_context =& $context; + } + + function expectContext($key, $value) { + $this->_expected_context[$key] = $value; + } + function expectContextAt($step, $key, $value) { + $this->_expected_context_at[$step][$key] = $value; + } + + function send($severity, $msg) { + // test for context + $test = &$this->_getCurrentTestCase(); + foreach ($this->_expected_context as $key => $value) { + $test->assertEqual($value, $this->_context->get($key)); + } + $step = $this->getCallCount('send'); + if (isset($this->_expected_context_at[$step])) { + foreach ($this->_expected_context_at[$step] as $key => $value) { + $test->assertEqual($value, $this->_context->get($key)); + } + } + // boilerplate mock code, does not have return value or references + $args = func_get_args(); + $this->_invoke('send', $args); + } + +} + diff --git a/tests/HTMLPurifier/ErrorCollectorTest.php b/tests/HTMLPurifier/ErrorCollectorTest.php dissimilarity index 65% index 31ac3052..508efcab 100644 --- a/tests/HTMLPurifier/ErrorCollectorTest.php +++ b/tests/HTMLPurifier/ErrorCollectorTest.php @@ -1,42 +1,141 @@ -line = 23; - $tok2 = new HTMLPurifier_Token_Start('a'); // also caused error - $tok2->line = 3; - $tok3 = new HTMLPurifier_Token_Text('Context before'); // before $tok2 - $tok3->line = 3; - $tok4 = new HTMLPurifier_Token_Text('Context after'); // after $tok2 - $tok4->line = 3; - - $collector = new HTMLPurifier_ErrorCollector(); - $collector->send('Big fat error', $tok1); - $collector->send('Another ', $tok2, array($tok3, true, $tok4)); - - $result = array( - 0 => array('Big fat error', $tok1, array(true)), - 1 => array('Another ', $tok2, array($tok3, true, $tok4)) - ); - - $this->assertIdentical($collector->getRaw(), $result); - - $formatted_result = array( - 0 => 'Another <error> at line 3 (Context before<a>Context after)', - 1 => 'Big fat error at line 23 (Token that caused error)' - ); - - $config = HTMLPurifier_Config::create(array('Core.MaintainLineNumbers' => true)); - $this->assertIdentical($collector->getHTMLFormatted($config), $formatted_result); - - } - -} - -?> \ No newline at end of file +setReturnValue('getErrorName', 'Error', array(E_ERROR)); + $language->setReturnValue('getErrorName', 'Warning', array(E_WARNING)); + $language->setReturnValue('getMessage', 'Message 1', array('message-1')); + $language->setReturnValue('formatMessage', 'Message 2', array('message-2', array(1 => 'param'))); + $language->setReturnValue('formatMessage', ' at line 23', array('ErrorCollector: At line', array('line' => 23))); + $language->setReturnValue('formatMessage', ' at line 3', array('ErrorCollector: At line', array('line' => 3))); + + $line = false; + + $context = new HTMLPurifier_Context(); + $context->register('Locale', $language); + $context->register('CurrentLine', $line); + + $generator = new HTMLPurifier_Generator(); + $context->register('Generator', $generator); + + $collector = new HTMLPurifier_ErrorCollector($context); + + $line = 23; + $collector->send(E_ERROR, 'message-1'); + + $line = 3; + $collector->send(E_WARNING, 'message-2', 'param'); + + $result = array( + 0 => array(23, E_ERROR, 'Message 1'), + 1 => array(3, E_WARNING, 'Message 2') + ); + + $this->assertIdentical($collector->getRaw(), $result); + + $formatted_result = + '
  • Warning: Message 2 at line 3
  • '. + '
  • Error: Message 1 at line 23
'; + + $config = HTMLPurifier_Config::create(array('Core.MaintainLineNumbers' => true)); + + $this->assertIdentical($collector->getHTMLFormatted($config), $formatted_result); + + } + + function testNoErrors() { + $language = new HTMLPurifier_LanguageMock(); + $language->setReturnValue('getMessage', 'No errors', array('ErrorCollector: No errors')); + $context = new HTMLPurifier_Context(); + $context->register('Locale', $language); + + $generator = new HTMLPurifier_Generator(); + $context->register('Generator', $generator); + + $collector = new HTMLPurifier_ErrorCollector($context); + $formatted_result = '

No errors

'; + $config = HTMLPurifier_Config::createDefault(); + $this->assertIdentical($collector->getHTMLFormatted($config), $formatted_result); + } + + function testNoLineNumbers() { + $language = new HTMLPurifier_LanguageMock(); + $language->setReturnValue('getMessage', 'Message 1', array('message-1')); + $language->setReturnValue('getMessage', 'Message 2', array('message-2')); + $language->setReturnValue('getErrorName', 'Error', array(E_ERROR)); + $context = new HTMLPurifier_Context(); + $context->register('Locale', $language); + + $generator = new HTMLPurifier_Generator(); + $context->register('Generator', $generator); + + $collector = new HTMLPurifier_ErrorCollector($context); + $collector->send(E_ERROR, 'message-1'); + $collector->send(E_ERROR, 'message-2'); + + $result = array( + 0 => array(null, E_ERROR, 'Message 1'), + 1 => array(null, E_ERROR, 'Message 2') + ); + $this->assertIdentical($collector->getRaw(), $result); + + $formatted_result = + '
  • Error: Message 1
  • '. + '
  • Error: Message 2
'; + $config = HTMLPurifier_Config::createDefault(); + $this->assertIdentical($collector->getHTMLFormatted($config), $formatted_result); + } + + function testContextSubstitutions() { + + $language = new HTMLPurifier_LanguageMock(); + $context = new HTMLPurifier_Context(); + $context->register('Locale', $language); + + $generator = new HTMLPurifier_Generator(); + $context->register('Generator', $generator); + + $current_token = false; + $context->register('CurrentToken', $current_token); + + $collector = new HTMLPurifier_ErrorCollector($context); + + // 0 + $current_token = new HTMLPurifier_Token_Start('a', array('href' => 'http://example.com'), 32); + $language->setReturnValue('formatMessage', 'Token message', + array('message-data-token', array('CurrentToken' => $current_token))); + $collector->send(E_NOTICE, 'message-data-token'); + + $current_attr = 'href'; + $language->setReturnValue('formatMessage', '$CurrentAttr.Name => $CurrentAttr.Value', + array('message-attr', array('CurrentToken' => $current_token))); + + // 1 + $collector->send(E_NOTICE, 'message-attr'); // test when context isn't available + + // 2 + $context->register('CurrentAttr', $current_attr); + $collector->send(E_NOTICE, 'message-attr'); + + $result = array( + 0 => array(32, E_NOTICE, 'Token message'), + 1 => array(32, E_NOTICE, '$CurrentAttr.Name => $CurrentAttr.Value'), + 2 => array(32, E_NOTICE, 'href => http://example.com') + ); + $this->assertIdentical($collector->getRaw(), $result); + + } + +} + diff --git a/tests/HTMLPurifier/ErrorsHarness.php b/tests/HTMLPurifier/ErrorsHarness.php new file mode 100644 index 00000000..359492a3 --- /dev/null +++ b/tests/HTMLPurifier/ErrorsHarness.php @@ -0,0 +1,31 @@ +config = HTMLPurifier_Config::create(array('Core.CollectErrors' => true)); + $this->context = new HTMLPurifier_Context(); + generate_mock_once('HTMLPurifier_ErrorCollector'); + $this->collector = new HTMLPurifier_ErrorCollectorEMock(); + $this->collector->prepare($this->context); + $this->context->register('ErrorCollector', $this->collector); + } + + function expectErrorCollection() { + $args = func_get_args(); + $this->collector->expectOnce('send', $args); + } + + function expectContext($key, $value) { + $this->collector->expectContext($key, $value); + } + +} + diff --git a/tests/HTMLPurifier/GeneratorTest.php b/tests/HTMLPurifier/GeneratorTest.php index 2656e82f..9039d1fb 100644 --- a/tests/HTMLPurifier/GeneratorTest.php +++ b/tests/HTMLPurifier/GeneratorTest.php @@ -141,9 +141,31 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness new HTMLPurifier_Token_Text('alert(3 < 5);'), new HTMLPurifier_Token_End('script') ), - "" + "" ); + // if missing close tag, don't do anything + $this->assertGeneration( + array( + new HTMLPurifier_Token_Start('script'), + new HTMLPurifier_Token_Text('alert(3 < 5);'), + ), + "" + ); + + + $this->config = HTMLPurifier_Config::createDefault(); $this->config->set('Core', 'CommentScriptContents', false); @@ -185,6 +207,7 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness $this->config = HTMLPurifier_Config::createDefault(); $this->config->set('Core', 'TidyFormat', true); + $this->config->set('Output', 'Newline', "\n"); // nice wrapping please $this->assertGeneration( @@ -200,4 +223,3 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/HTMLDefinitionTest.php b/tests/HTMLPurifier/HTMLDefinitionTest.php index 13804472..3581f8cf 100644 --- a/tests/HTMLPurifier/HTMLDefinitionTest.php +++ b/tests/HTMLPurifier/HTMLDefinitionTest.php @@ -84,4 +84,3 @@ class HTMLPurifier_HTMLDefinitionTest extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/HTMLModule/ScriptingTest.php b/tests/HTMLPurifier/HTMLModule/ScriptingTest.php index 70008d1e..2bb4a0e8 100644 --- a/tests/HTMLPurifier/HTMLModule/ScriptingTest.php +++ b/tests/HTMLPurifier/HTMLModule/ScriptingTest.php @@ -18,6 +18,14 @@ class HTMLPurifier_HTMLModule_ScriptingTest extends HTMLPurifier_HTMLModuleHarne array('HTML.Trusted' => true) ); + // CDATA + $this->assertResult( +'//"); +//]]> ', true, + array('HTML.Trusted' => true) + ); + // max $this->assertResult( '', - '', - array('HTML.Trusted' => true, 'Core.CommentScriptContents' => false) - ); - } } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/HTMLModule/TidyTest.php b/tests/HTMLPurifier/HTMLModule/TidyTest.php index f3a1f977..ff8d844d 100644 --- a/tests/HTMLPurifier/HTMLModule/TidyTest.php +++ b/tests/HTMLPurifier/HTMLModule/TidyTest.php @@ -45,7 +45,7 @@ class HTMLPurifier_HTMLModule_TidyTest extends UnitTestCase $i = 0; // counter, helps us isolate expectations // initialize partial mock - $module = new HTMLPurifier_HTMLModule_Tidy_TestForConstruct($this); + $module = new HTMLPurifier_HTMLModule_Tidy_TestForConstruct(); $module->fixesForLevel['light'] = array('light-fix-1', 'light-fix-2'); $module->fixesForLevel['medium'] = array('medium-fix-1', 'medium-fix-2'); $module->fixesForLevel['heavy'] = array('heavy-fix-1', 'heavy-fix-2'); @@ -227,4 +227,3 @@ class HTMLPurifier_HTMLModule_TidyTest extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/HTMLModuleHarness.php b/tests/HTMLPurifier/HTMLModuleHarness.php index 1f60f435..8ca2df33 100644 --- a/tests/HTMLPurifier/HTMLModuleHarness.php +++ b/tests/HTMLPurifier/HTMLModuleHarness.php @@ -11,4 +11,3 @@ class HTMLPurifier_HTMLModuleHarness extends HTMLPurifier_StrategyHarness } } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/HTMLModuleManagerTest.php b/tests/HTMLPurifier/HTMLModuleManagerTest.php index c273856a..d5219ca1 100644 --- a/tests/HTMLPurifier/HTMLModuleManagerTest.php +++ b/tests/HTMLPurifier/HTMLModuleManagerTest.php @@ -13,7 +13,7 @@ class HTMLPurifier_HTMLModuleManagerTest extends UnitTestCase $attrdef_nmtokens->_name = 'nmtokens'; // for testing only generate_mock_once('HTMLPurifier_AttrDef'); - $attrdef = new HTMLPurifier_AttrDefMock($this); + $attrdef = new HTMLPurifier_AttrDefMock(); $attrdef->setReturnValue('make', $attrdef_nmtokens); $manager->attrTypes->info['NMTOKENS'] =& $attrdef; @@ -38,7 +38,7 @@ class HTMLPurifier_HTMLModuleManagerTest extends UnitTestCase $config = HTMLPurifier_Config::createDefault(); $config->set('HTML', 'Trusted', false); - $config->set('HTML', 'Doctype', 'Blank'); + $config->set('HTML', 'CustomDoctype', 'Blank'); $manager->setup($config); @@ -94,7 +94,7 @@ class HTMLPurifier_HTMLModuleManagerTest extends UnitTestCase $manager->registerModule($magic_module); $config = HTMLPurifier_Config::create(array( - 'HTML.Doctype' => 'Fantasy Inventory 1.0', + 'HTML.CustomDoctype' => 'Fantasy Inventory 1.0', 'HTML.AllowedModules' => 'Weapons' )); $manager->setup($config); @@ -106,4 +106,3 @@ class HTMLPurifier_HTMLModuleManagerTest extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/HTMLModuleTest.php b/tests/HTMLPurifier/HTMLModuleTest.php index 9e0b7100..238ca42a 100644 --- a/tests/HTMLPurifier/HTMLModuleTest.php +++ b/tests/HTMLPurifier/HTMLModuleTest.php @@ -147,4 +147,3 @@ class HTMLPurifier_HTMLModuleTest extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/Harness.php b/tests/HTMLPurifier/Harness.php index c591db32..84cea5eb 100644 --- a/tests/HTMLPurifier/Harness.php +++ b/tests/HTMLPurifier/Harness.php @@ -47,6 +47,11 @@ class HTMLPurifier_Harness extends UnitTestCase */ var $config; + /** + * Default context to fall back on if no context is available + */ + var $context; + function HTMLPurifier_Harness() { $this->lexer = new HTMLPurifier_Lexer_DirectLex(); $this->generator = new HTMLPurifier_Generator(); @@ -77,8 +82,12 @@ class HTMLPurifier_Harness extends UnitTestCase // setup context object. Note that we are operating on a copy of it! // When necessary, extend the test harness to allow post-tests // on the context object - $context = new HTMLPurifier_Context(); - $context->loadArray($context_array); + if (empty($this->context)) { + $context = new HTMLPurifier_Context(); + $context->loadArray($context_array); + } else { + $context =& $this->context; + } if ($this->to_tokens && is_string($input)) { // $func may cause $input to change, so "clone" another copy @@ -116,4 +125,4 @@ class HTMLPurifier_Harness extends UnitTestCase } -?> + diff --git a/tests/HTMLPurifier/IDAccumulatorTest.php b/tests/HTMLPurifier/IDAccumulatorTest.php index 8ff04545..05db0b2a 100644 --- a/tests/HTMLPurifier/IDAccumulatorTest.php +++ b/tests/HTMLPurifier/IDAccumulatorTest.php @@ -32,4 +32,3 @@ class HTMLPurifier_IDAccumulatorTest extends UnitTestCase } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/Injector/AutoParagraphTest.php b/tests/HTMLPurifier/Injector/AutoParagraphTest.php new file mode 100644 index 00000000..8611fd9b --- /dev/null +++ b/tests/HTMLPurifier/Injector/AutoParagraphTest.php @@ -0,0 +1,253 @@ +config = array('AutoFormat.AutoParagraph' => true); + } + + function test() { + $this->assertResult( + 'Foobar', + '

Foobar

' + ); + + $this->assertResult( +'Par 1 +Par 1 still', +'

Par 1 +Par 1 still

' + ); + + $this->assertResult( +'Par1 + +Par2', + '

Par1

Par2

' + ); + + $this->assertResult( +'Par1 + + + +Par2', + '

Par1

Par2

' + ); + + $this->assertResult( +'Par1 + +Par2', + '

Par1

Par2

' + ); + + + $this->assertResult( +'Par1 + +Par2', +'

Par1 + +Par2

' + ); + + $this->assertResult( + 'Par1

Par2

', + '

Par1

Par2

' + ); + + $this->assertResult( + 'Par1', + '

Par1

' + ); + + $this->assertResult( +'
Par1
+
+Par1
' + ); + + $this->assertResult( +'Par1 + + ', +'

Par1

' + ); + $this->assertResult( +'Par1 + +
Par2
+ +Par3', +'

Par1

Par2

Par3

' + ); + + $this->assertResult( +'Par1', + '

Par1

' + ); + + $this->assertResult( +' + +Par', + '

Par

' + ); + + $this->assertResult( +' + +Par + +', + '

Par

' + ); + + $this->assertResult( +'
Par1 + +Par2
', + '

Par1

Par2

' + ); + + $this->assertResult( +'
Par1 + +Par2
', + '

Par1

Par2

' + ); + + $this->assertResult('
Par1
'); + + $this->assertResult( +'
Par1 + +Par2
', + '

Par1

Par2

' + ); + + $this->assertResult( +'
Par1
+
+Par2
', + true + ); + + $this->assertResult( +'

Foo + +Bar

', + '

Foo

Bar

' + ); + + $this->assertResult( +'

Foo + +Bar

', + '

Foo

Bar

' + ); + + $this->assertResult( +'
Foo
', + '
Foo
' + ); + + $this->assertResult( +'
Par1 + +Par2
', + '

Par1

Par2

' + ); + + $this->assertResult( +'
  • Foo
  • + +
  • Bar
', true + ); + + $this->assertResult( +'
+ +Bar + +
', + '

Bar

' + ); + + $this->assertResult( +'Par1a + + + +Par2', + '

Par1a

Par2

' + ); + + $this->assertResult( +'Par1 + +Par2

', + '

Par1

Par2

' + ); + + $this->assertResult( +'Par1 + +Par2', + '

Par1

Par2

' + ); + + $this->assertResult( +'
+Par1 +
', true + ); + + $this->assertResult( +'
Par1 + +
Par2
', +'

Par1

Par2
' + ); + + $this->assertResult( +'
Par1 +
Par2
', +'

Par1 +

Par2
' + ); + + $this->assertResult( +'Par1 +
Par2
', +'

Par1 +

Par2
' + ); + + $this->assertResult( +'Par1 + +Par2', +'

Par1

Par2

' + ); + + } + + function testInlineRootNode() { + $this->assertResult( +'Par + +Par2', + true, + array('AutoFormat.AutoParagraph' => true, 'HTML.Parent' => 'span') + ); + } + +} + diff --git a/tests/HTMLPurifier/Injector/LinkifyTest.php b/tests/HTMLPurifier/Injector/LinkifyTest.php new file mode 100644 index 00000000..b91908ee --- /dev/null +++ b/tests/HTMLPurifier/Injector/LinkifyTest.php @@ -0,0 +1,38 @@ +config = array('AutoFormat.Linkify' => true); + } + + function testLinkify() { + + $this->assertResult( + 'http://example.com', + '
http://example.com' + ); + + $this->assertResult( + 'http://example.com', + 'http://example.com' + ); + + $this->assertResult( + 'This URL http://example.com is what you need', + 'This URL http://example.com is what you need' + ); + + $this->assertResult( + 'http://example.com/' + ); + + } + +} + diff --git a/tests/HTMLPurifier/Injector/PurifierLinkifyTest.php b/tests/HTMLPurifier/Injector/PurifierLinkifyTest.php new file mode 100644 index 00000000..d538c489 --- /dev/null +++ b/tests/HTMLPurifier/Injector/PurifierLinkifyTest.php @@ -0,0 +1,42 @@ +config = array( + 'AutoFormat.PurifierLinkify' => true, + 'AutoFormatParam.PurifierLinkifyDocURL' => '#%s' + ); + } + + function testLinkify() { + + $this->assertResult('Foobar'); + $this->assertResult('20% off!'); + $this->assertResult('%Core namespace (not recognized)'); + $this->assertResult( + '%Namespace.Directive', + '%Namespace.Directive' + ); + $this->assertResult( + 'This %Namespace.Directive thing', + 'This %Namespace.Directive thing' + ); + $this->assertResult( + '
This %Namespace.Directive thing
', + '' + ); + $this->assertResult( + '%Namespace.Directive' + ); + + + } + +} + diff --git a/tests/HTMLPurifier/InjectorHarness.php b/tests/HTMLPurifier/InjectorHarness.php new file mode 100644 index 00000000..1b20b126 --- /dev/null +++ b/tests/HTMLPurifier/InjectorHarness.php @@ -0,0 +1,15 @@ +obj = new HTMLPurifier_Strategy_MakeWellFormed(); + } + +} + diff --git a/tests/HTMLPurifier/LanguageFactoryTest.php b/tests/HTMLPurifier/LanguageFactoryTest.php index 1355b5d9..eb0f4556 100644 --- a/tests/HTMLPurifier/LanguageFactoryTest.php +++ b/tests/HTMLPurifier/LanguageFactoryTest.php @@ -9,7 +9,9 @@ class HTMLPurifier_LanguageFactoryTest extends UnitTestCase $factory = HTMLPurifier_LanguageFactory::instance(); - $language = $factory->create('en'); + $config = HTMLPurifier_Config::create(array('Core.Language' => 'en')); + $context = new HTMLPurifier_Context(); + $language = $factory->create($config, $context); $this->assertIsA($language, 'HTMLPurifier_Language'); $this->assertIdentical($language->code, 'en'); @@ -27,7 +29,10 @@ class HTMLPurifier_LanguageFactoryTest extends UnitTestCase $factory = HTMLPurifier_LanguageFactory::instance(); - $language = $factory->create('en-x-test'); + $config = HTMLPurifier_Config::create(array('Core.Language' => 'en-x-test')); + $context = new HTMLPurifier_Context(); + + $language = $factory->create($config, $context); $this->assertIsA($language, 'HTMLPurifier_Language_en_x_test'); $this->assertIdentical($language->code, 'en-x-test'); @@ -35,13 +40,12 @@ class HTMLPurifier_LanguageFactoryTest extends UnitTestCase $language->load(); // test overloaded message - $this->assertIdentical($language->getMessage('htmlpurifier'), 'HTML Purifier X'); + $this->assertIdentical($language->getMessage('HTMLPurifier'), 'HTML Purifier X'); // test inherited message - $this->assertIdentical($language->getMessage('pizza'), 'Pizza'); + $this->assertIdentical($language->getMessage('LanguageFactoryTest: Pizza'), 'Pizza'); } } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/LanguageTest.php b/tests/HTMLPurifier/LanguageTest.php dissimilarity index 61% index 21e55206..f846c619 100644 --- a/tests/HTMLPurifier/LanguageTest.php +++ b/tests/HTMLPurifier/LanguageTest.php @@ -1,27 +1,77 @@ -_loaded = true; - $lang->messages['htmlpurifier'] = 'HTML Purifier'; - $this->assertIdentical($lang->getMessage('htmlpurifier'), 'HTML Purifier'); - $this->assertIdentical($lang->getMessage('totally-non-existent-key'), '[totally-non-existent-key]'); - } - - function test_formatMessage() { - $lang = new HTMLPurifier_Language(); - $lang->_loaded = true; - $lang->messages['error'] = 'Error is $1 on line $2'; - $this->assertIdentical($lang->formatMessage('error', 'fatal', 32), 'Error is fatal on line 32'); - } - -} - -?> \ No newline at end of file + 'en')); + $context = new HTMLPurifier_Context(); + return $factory->create($config, $context); + } + + function test_getMessage() { + $config = HTMLPurifier_Config::createDefault(); + $context = new HTMLPurifier_Context(); + $lang = new HTMLPurifier_Language($config, $context); + $lang->_loaded = true; + $lang->messages['HTMLPurifier'] = 'HTML Purifier'; + $this->assertIdentical($lang->getMessage('HTMLPurifier'), 'HTML Purifier'); + $this->assertIdentical($lang->getMessage('LanguageTest: Totally non-existent key'), '[LanguageTest: Totally non-existent key]'); + } + + function test_formatMessage() { + $config = HTMLPurifier_Config::createDefault(); + $context = new HTMLPurifier_Context(); + $lang = new HTMLPurifier_Language($config, $context); + $lang->_loaded = true; + $lang->messages['LanguageTest: Error'] = 'Error is $1 on line $2'; + $this->assertIdentical($lang->formatMessage('LanguageTest: Error', array(1=>'fatal', 32)), 'Error is fatal on line 32'); + } + + function test_formatMessage_tokenParameter() { + $config = HTMLPurifier_Config::createDefault(); + $context = new HTMLPurifier_Context(); + $generator = new HTMLPurifier_Generator(); // replace with mock if this gets icky + $context->register('Generator', $generator); + $lang = new HTMLPurifier_Language($config, $context); + $lang->_loaded = true; + $lang->messages['LanguageTest: Element info'] = 'Element Token: $1.Name, $1.Serialized, $1.Compact, $1.Line'; + $lang->messages['LanguageTest: Data info'] = 'Data Token: $1.Data, $1.Serialized, $1.Compact, $1.Line'; + $this->assertIdentical($lang->formatMessage('LanguageTest: Element info', + array(1=>new HTMLPurifier_Token_Start('a', array('href'=>'http://example.com'), 18))), + 'Element Token: a, , , 18'); + $this->assertIdentical($lang->formatMessage('LanguageTest: Data info', + array(1=>new HTMLPurifier_Token_Text('data>', 23))), + 'Data Token: data>, data>, data>, 23'); + } + + function test_listify() { + $lang = $this->generateEnLanguage(); + $this->assertEqual($lang->listify(array('Item')), 'Item'); + $this->assertEqual($lang->listify(array('Item', 'Item2')), 'Item and Item2'); + $this->assertEqual($lang->listify(array('Item', 'Item2', 'Item3')), 'Item, Item2 and Item3'); + } + + function test_formatMessage_arrayParameter() { + $lang = $this->generateEnLanguage(); + + $array = array('Item1', 'Item2', 'Item3'); + $this->assertIdentical( + $lang->formatMessage('LanguageTest: List', array(1=>$array)), + 'Item1, Item2 and Item3' + ); + + $array = array('Key1' => 'Value1', 'Key2' => 'Value2'); + $this->assertIdentical( + $lang->formatMessage('LanguageTest: Hash', array(1=>$array)), + 'Key1 and Key2; Value1 and Value2' + ); + } + +} + diff --git a/tests/HTMLPurifier/Lexer/DirectLexTest.php b/tests/HTMLPurifier/Lexer/DirectLexTest.php index 37c516f3..ba7d0fe7 100644 --- a/tests/HTMLPurifier/Lexer/DirectLexTest.php +++ b/tests/HTMLPurifier/Lexer/DirectLexTest.php @@ -53,6 +53,12 @@ class HTMLPurifier_Lexer_DirectLexTest extends UnitTestCase $input[10] = 'name="input" selected'; $expect[10] = array('name' => 'input', 'selected' => 'selected'); + $input[11] = '=""'; + $expect[11] = array(); + + $input[12] = '="" =""'; + $expect[12] = array('"' => ''); // tough to say, just don't throw a loop + $config = HTMLPurifier_Config::createDefault(); $context = new HTMLPurifier_Context(); $size = count($input); @@ -66,32 +72,23 @@ class HTMLPurifier_Lexer_DirectLexTest extends UnitTestCase function testLineNumbers() { - $html = 'Line 1 - Line 2 - Still Line 2
Now Line 4 - -
'; + $html = "Line 1\nLine 2\nStill Line 2Now Line 4\n\n
"; $expect = array( // line 1 0 => new HTMLPurifier_Token_Start('b') ,1 => new HTMLPurifier_Token_Text('Line 1') ,2 => new HTMLPurifier_Token_End('b') - ,3 => new HTMLPurifier_Token_Text(' - ') + ,3 => new HTMLPurifier_Token_Text("\n") // line 2 ,4 => new HTMLPurifier_Token_Start('i') ,5 => new HTMLPurifier_Token_Text('Line 2') ,6 => new HTMLPurifier_Token_End('i') - ,7 => new HTMLPurifier_Token_Text(' - Still Line 2') + ,7 => new HTMLPurifier_Token_Text("\nStill Line 2") // line 3 ,8 => new HTMLPurifier_Token_Empty('br') // line 4 - ,9 => new HTMLPurifier_Token_Text('Now Line 4 - - ') + ,9 => new HTMLPurifier_Token_Text("Now Line 4\n\n") // line SIX ,10 => new HTMLPurifier_Token_Empty('br') ); @@ -123,7 +120,5 @@ class HTMLPurifier_Lexer_DirectLexTest extends UnitTestCase } - } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/Lexer/DirectLex_ErrorsTest.php b/tests/HTMLPurifier/Lexer/DirectLex_ErrorsTest.php new file mode 100644 index 00000000..ad048d2d --- /dev/null +++ b/tests/HTMLPurifier/Lexer/DirectLex_ErrorsTest.php @@ -0,0 +1,55 @@ +tokenizeHTML($input, $this->config, $this->context); + } + + function invokeAttr($input) { + $lexer = new HTMLPurifier_Lexer_DirectLex(); + $lexer->parseAttributeString($input, $this->config, $this->context); + } + + function testUnclosedComment() { + $this->expectErrorCollection(E_WARNING, 'Lexer: Unclosed comment'); + $this->expectContext('CurrentLine', 1); + $this->invoke('
'; + $expect[20] = array( + new HTMLPurifier_Token_Comment(' This >< comment '), + new HTMLPurifier_Token_Empty('br') + ); + $sax_expect[20] = false; + + // test comment parsing of missing end + $input[21] = '', +'', + array('HTML.Trusted' => true, 'Output.CommentScriptContents' => false) + ); + } } -?> \ No newline at end of file diff --git a/tests/HTMLPurifier/Strategy/RemoveForeignElements_ErrorsTest.php b/tests/HTMLPurifier/Strategy/RemoveForeignElements_ErrorsTest.php new file mode 100644 index 00000000..6b7ac74f --- /dev/null +++ b/tests/HTMLPurifier/Strategy/RemoveForeignElements_ErrorsTest.php @@ -0,0 +1,59 @@ +config->set('HTML', 'TidyLevel', 'heavy'); + } + + function getStrategy() { + return new HTMLPurifier_Strategy_RemoveForeignElements(); + } + + function testTagTransform() { + $this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Tag transform', 'center'); + $this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('div', array('style' => 'text-align:center;'), 1)); + $this->invoke('
'); + } + + function testMissingRequiredAttr() { + // a little fragile, since img has two required attributes + $this->expectErrorCollection(E_ERROR, 'Strategy_RemoveForeignElements: Missing required attribute', 'alt'); + $this->expectContext('CurrentToken', new HTMLPurifier_Token_Empty('img', array(), 1)); + $this->invoke(''); + } + + function testForeignElementToText() { + $this->config->set('Core', 'EscapeInvalidTags', true); + $this->expectErrorCollection(E_WARNING, 'Strategy_RemoveForeignElements: Foreign element to text'); + $this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('invalid', array(), 1)); + $this->invoke(''); + } + + function testForeignElementRemoved() { + // uses $CurrentToken.Serialized + $this->expectErrorCollection(E_ERROR, 'Strategy_RemoveForeignElements: Foreign element removed'); + $this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('invalid', array(), 1)); + $this->invoke(''); + } + + function testCommentRemoved() { + $this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Comment removed'); + $this->expectContext('CurrentToken', new HTMLPurifier_Token_Comment(' test ', 1)); + $this->invoke(''); + } + + function testScriptRemoved() { + $this->collector->expectAt(0, 'send', array(E_ERROR, 'Strategy_RemoveForeignElements: Script removed')); + $this->collector->expectContextAt(0, 'CurrentToken', new HTMLPurifier_Token_Start('script', array(), 1)); + $this->collector->expectAt(1, 'send', array(E_ERROR, 'Strategy_RemoveForeignElements: Token removed to end', 'script')); + $this->invoke(''; + + $this->assertPurification($ideal); + + $this->assertPurification( + '', + $ideal + ); + + $this->assertPurification( + '', + $ideal + ); + + $this->assertPurification( + '', + $ideal + ); + + $this->assertPurification( + '', + $ideal + ); + } + } -?> \ No newline at end of file diff --git a/tests/generate_mock_once.func.php b/tests/generate_mock_once.func.php index 3e4d5b6d..1c74340b 100644 --- a/tests/generate_mock_once.func.php +++ b/tests/generate_mock_once.func.php @@ -8,4 +8,3 @@ function generate_mock_once($name) { Mock::generate($name, $mock_name); } -?> \ No newline at end of file diff --git a/tests/index.php b/tests/index.php index e823a347..aad6a94c 100644 --- a/tests/index.php +++ b/tests/index.php @@ -84,4 +84,4 @@ else $reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8'); $test->run($reporter); -?> + diff --git a/tests/path2class.func.php b/tests/path2class.func.php index 1fad4ea6..4680e422 100644 --- a/tests/path2class.func.php +++ b/tests/path2class.func.php @@ -11,4 +11,3 @@ function path2class($path) { return $temp; } -?> \ No newline at end of file diff --git a/tests/tally_errors.func.php b/tests/tally_errors.func.php index cd945c3d..562d69b9 100644 --- a/tests/tally_errors.func.php +++ b/tests/tally_errors.func.php @@ -15,4 +15,3 @@ function tally_errors($test) { $queue->_expectation_queue = array(); } -?> \ No newline at end of file diff --git a/tests/test_files.php b/tests/test_files.php index c2c8bada..5920981e 100644 --- a/tests/test_files.php +++ b/tests/test_files.php @@ -52,6 +52,7 @@ $test_files[] = 'HTMLPurifier/AttrTransform/LangTest.php'; $test_files[] = 'HTMLPurifier/AttrTransform/LengthTest.php'; $test_files[] = 'HTMLPurifier/AttrTransform/NameTest.php'; $test_files[] = 'HTMLPurifier/AttrTypesTest.php'; +$test_files[] = 'HTMLPurifier/AttrValidator_ErrorsTest.php'; $test_files[] = 'HTMLPurifier/ChildDef/ChameleonTest.php'; $test_files[] = 'HTMLPurifier/ChildDef/CustomTest.php'; $test_files[] = 'HTMLPurifier/ChildDef/OptionalTest.php'; @@ -81,16 +82,23 @@ $test_files[] = 'HTMLPurifier/HTMLModuleTest.php'; $test_files[] = 'HTMLPurifier/HTMLModule/ScriptingTest.php'; $test_files[] = 'HTMLPurifier/HTMLModule/TidyTest.php'; $test_files[] = 'HTMLPurifier/IDAccumulatorTest.php'; +$test_files[] = 'HTMLPurifier/Injector/AutoParagraphTest.php'; +$test_files[] = 'HTMLPurifier/Injector/LinkifyTest.php'; +$test_files[] = 'HTMLPurifier/Injector/PurifierLinkifyTest.php'; $test_files[] = 'HTMLPurifier/LanguageFactoryTest.php'; $test_files[] = 'HTMLPurifier/LanguageTest.php'; $test_files[] = 'HTMLPurifier/Lexer/DirectLexTest.php'; +$test_files[] = 'HTMLPurifier/Lexer/DirectLex_ErrorsTest.php'; $test_files[] = 'HTMLPurifier/LexerTest.php'; $test_files[] = 'HTMLPurifier/PercentEncoderTest.php'; $test_files[] = 'HTMLPurifier/Strategy/CompositeTest.php'; $test_files[] = 'HTMLPurifier/Strategy/CoreTest.php'; $test_files[] = 'HTMLPurifier/Strategy/FixNestingTest.php'; +$test_files[] = 'HTMLPurifier/Strategy/FixNesting_ErrorsTest.php'; $test_files[] = 'HTMLPurifier/Strategy/MakeWellFormedTest.php'; +$test_files[] = 'HTMLPurifier/Strategy/MakeWellFormed_ErrorsTest.php'; $test_files[] = 'HTMLPurifier/Strategy/RemoveForeignElementsTest.php'; +$test_files[] = 'HTMLPurifier/Strategy/RemoveForeignElements_ErrorsTest.php'; $test_files[] = 'HTMLPurifier/Strategy/ValidateAttributesTest.php'; $test_files[] = 'HTMLPurifier/TagTransformTest.php'; $test_files[] = 'HTMLPurifier/TokenTest.php'; @@ -106,4 +114,3 @@ if (version_compare(PHP_VERSION, '5', '>=')) { // ... none yet -?> \ No newline at end of file -- 2.11.4.GIT