From a01361b5ae9df5220c0ce7b42c5ff36094d5718c Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Mon, 1 Apr 2013 16:42:31 +0200 Subject: [PATCH] Added more tests for strip_tags utility Refs #19237. --- tests/utils_tests/files/strip_tags1.html | 1302 ++++++++++++++++++++++ tests/utils_tests/files/strip_tags2.txt | 118 ++ tests/utils_tests/html.py | 16 + 3 files changed, 1436 insertions(+) create mode 100644 tests/utils_tests/files/strip_tags1.html create mode 100644 tests/utils_tests/files/strip_tags2.txt diff --git a/tests/utils_tests/files/strip_tags1.html b/tests/utils_tests/files/strip_tags1.html new file mode 100644 index 0000000000..8e9ee1d8fd --- /dev/null +++ b/tests/utils_tests/files/strip_tags1.html @@ -0,0 +1,1302 @@ + + + + + + Improved regex in strip_tags · d7504a3 · django/django + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + + + + +
+ + + + +
+ + +
+
+ + + + + + + + + + +
+
+ +
+ + + + + + + + + +
+
+ +
+
+ +
+
+
+ + + +
    + +
  • + Pull Request +
  • + +
  • +
    + +
    + + + + Watch + + + +
    +
    +
    + Notification status + +
    + +
    + +
    + +
    + +

    Not watching

    + You only receive notifications for discussions in which you participate or are @mentioned. + + + Watch + +
    +
    + +
    + +
    + +

    Watching

    + You receive notifications for all discussions in this repository. + + + Unwatch + +
    +
    + +
    + +
    + +

    Ignoring

    + You do not receive any notifications for discussions in this repository. + + + Stop ignoring + +
    +
    + +
    + +
    +
    +
    + +
    +
  • + +
  • + + + Unstar + + + + Star + + +
  • + +
  • + + + Fork + + +
  • + + +
+ +

+ public + + + / + django +

+
+ + + + +
+ + + + + + +
+ + +
+ + + tree: + d7504a3d7b + + +
+ +
+
+ Switch branches/tags + +
+ +
+
+ +
+
+ +
+
+ + + + +
+
+ +
+ + 1.5c2 +
+
+ + 1.5c1 +
+
+ + 1.5b2 +
+
+ + 1.5b1 +
+
+ + 1.5a1 +
+
+ + 1.5.1 +
+
+ + 1.5 +
+
+ + 1.4.5 +
+
+ + 1.4.4 +
+
+ + 1.4.3 +
+
+ + 1.4.2 +
+
+ + 1.4.1 +
+
+ + 1.4 +
+
+ + 1.3.7 +
+
+ + 1.3.6 +
+
+ + 1.3.5 +
+
+ + 1.3.4 +
+
+ + 1.3.3 +
+
+ + 1.3.2 +
+
+ + 1.3.1 +
+
+ + 1.3 +
+
+ + 1.2.7 +
+
+ + 1.2.6 +
+
+ + 1.2.5 +
+
+ + 1.2.4 +
+
+ + 1.2.3 +
+
+ + 1.2.2 +
+
+ + 1.2.1 +
+
+ + 1.2 +
+
+ + 1.1.4 +
+
+ + 1.1.3 +
+
+ + 1.1.2 +
+
+ + 1.1.1 +
+
+ + 1.1 +
+
+ + 1.0.4 +
+
+ + 1.0.3 +
+
+ + 1.0.2 +
+
+ + 1.0.1 +
+
+ + 1.0 +
+
+ +
Nothing to show
+ +
+ +
+
+
+ +
+ + + +
+ + + + + + + +
+
+ +
+ + + +
+ Browse code + +

+ Improved regex in strip_tags +

+ +
Thanks Pablo Recio for the report. Refs #19237.
+ +
+ commit d7504a3d7b8645bdb979bab7ded0e9a9b6dccd0e + + + 1 parent + + afa3e16 + + +
+ + + authored + +
+
+
+ + + +
+

+ Showing 2 changed files + with 2 additions + and 1 deletion. + Show Diff Stats + Hide Diff Stats

+ +
    +
  1. + + + 2 +  + + + django/utils/html.py +
  2. +
  3. + + + 1 +  + + + tests/regressiontests/utils/html.py +
  4. +
+
+ + +
+
+
+
+ 2  + + + django/utils/html.py + + +
+
+ + + + +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ ... + + ... + + + @@ -33,7 +33,7 @@ +
+ 33 + + 33 + + +  html_gunk_re = re.compile(r'(?:<br clear="all">|<i><\/i>|<b><\/b>|<em><\/em>|<strong><\/strong>|<\/?smallcaps>|<\/?uppercase>)', re.IGNORECASE) +
+ 34 + + 34 + + +  hard_coded_bullets_re = re.compile(r'((?:<p>(?:%s).*?[a-zA-Z].*?</p>\s*)+)' % '|'.join([re.escape(x) for x in DOTS]), re.DOTALL) +
+ 35 + + 35 + + +  trailing_empty_content_re = re.compile(r'(?:<p>(?:&nbsp;|\s|<br \/>)*?</p>\s*)+\Z') +
+ 36 + +   + + + -strip_tags_re = re.compile(r'</?\S([^=]*=(\s*"[^"]*"|\s*\'[^\']*\'|\S*)|[^>])*?>', re.IGNORECASE) +
+   + + 36 + + + +strip_tags_re = re.compile(r'</?\S([^=>]*=(\s*"[^"]*"|\s*\'[^\']*\'|\S*)|[^>])*?>', re.IGNORECASE) +
+ 37 + + 37 + + +   +
+ 38 + + 38 + + +   +
+ 39 + + 39 + + +  def escape(text): +
+
+ +
+
+
+
+
+ 1  + + + tests/regressiontests/utils/html.py + + +
+
+ + + + +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ ... + + ... + + + @@ -68,6 +68,7 @@ def test_strip_tags(self): +
+ 68 + + 68 + + +              ('a<p onclick="alert(\'<test>\')">b</p>c', 'abc'), +
+ 69 + + 69 + + +              ('a<p a >b</p>c', 'abc'), +
+ 70 + + 70 + + +              ('d<a:b c:d>e</p>f', 'def'), +
+   + + 71 + + + +            ('<strong>foo</strong><a href="http://example.com">bar</a>', 'foobar'), +
+ 71 + + 72 + + +          ) +
+ 72 + + 73 + + +          for value, output in items: +
+ 73 + + 74 + + +              self.check_output(f, value, output) +
+
+ +
+
+
+ + +
+ + +

+ 0 notes + on commit d7504a3 + +

+
+
+ +
+ + +
+
+
+ + + +
+
+ + + Comments are parsed with GitHub Flavored Markdown + +
+ + +
+ + + + + + + + +

+ + Attach images by dragging & dropping them or + + choose an image + + + Octocat-spinner-32 Uploading your images now… + + + Unfortunately we don't support that file type yet. Try image files less than 5MB. + + + This browser doesn't support image attachments. + + + Something went really wrong and we can't process that image. + +

+ +
+
+ +
+ + + +
+
+
+

Nothing to preview

+
+
+
+
+ +
+ +
+
+
+
+
+ +
+
+ +
+
+ Commit_comment_tip +

Tip: You can also add notes to lines in a file. Hover to the left of a line to make a note

+
+ +
+
+ + + +
+ + + +
+ + +
+ +
+ + + + + + + Watch thread + + + +
+
+
+ Thread notifications + +
+ +
+ +
+ +
+ +

Not watching

+ You only receive notifications for this thread if you participate or are @mentioned. + + + Watch thread + +
+
+ +
+ +
+ +

Watching

+ Receive all notifications for this thread. + + + Unwatch thread + +
+
+ +
+ +
+ +

Ignoring

+ You do not receive notifications for this thread. + + + Stop ignoring thread + +
+
+ +
+
+
+
+ +

You only receive notifications for this thread when you participate or are @mentioned.

+
+ + + + + + + +
+
+
+
+ + +
+ + + + + +
+
+
+ +
+
+
+
+
+
+ +
+ + + +
+ + Something went wrong with that request. Please try again. + +
+ + + + + + + + diff --git a/tests/utils_tests/files/strip_tags2.txt b/tests/utils_tests/files/strip_tags2.txt new file mode 100644 index 0000000000..6b2a4033c2 --- /dev/null +++ b/tests/utils_tests/files/strip_tags2.txt @@ -0,0 +1,118 @@ +_**Prerequisite**: You are already aware of the [basics of building a HelloWorld](http://developer.android.com/training/index.html) in Android and know [how to use the APIs provided in the support library](http://developer.android.com/training/basics/fragments/support-lib.html)._ + +_The code example is available on [github](http://github.com/iontech/Fragments_Example "Fragments Example")._ +_____________________________________________________________ +Ever wanted a code snippet from an Activity to be available to other activities? Perhaps a Button or a ListView, maybe a Layout or any View/ViewGroup for that matter? Fragments let us do just that. + +Necessity is the mother of invention. +Before understanding what Fragments are and how they work, we must first realize their existence in the first place. + +The Problem +----------- +Suppose we have an Android app with two Activities- [*FirstActivity*](https://github.com/iontech/Fragments_Example/blob/master/src/main/java/com/github/iontech/fragments_example/FirstActivity.java) and [*SecondActivity*](https://github.com/iontech/Fragments_Example/blob/master/src/main/java/com/github/iontech/fragments_example/SecondActivity.java). +*FirstActivity* contains two Views, a `TextView` (*textView*) and a `Button` (*button1*); and *button1* has an `onClick()` callback that `Toast`'s a simple message "Button pressed". +*SecondActivity* contains both the Views present in *FirstActivity* and a `Button` (*button2*). + +Now we want to utilize the two layout components(Views) of *FirstActivity* in *SecondActivity*, we can go about this with two approaches: + +1. Copy and Paste the xml elements of the two Views. +2. Create a separate layout for common Views and reuse it using `` layout element. + More about this [here](http://developer.android.com/training/improving-layouts/reusing-layouts.html). + +Electing the second approach makes sense cause it enables us to make reusable layouts. Everything seems great till now. We are able to make reusable layouts and use them as many times as we want. + +Now recollect that we have an `onClick()` callback assigned to *button1*. How do we reuse the same callback functionality of *button1* across multiple Activities? `` lets us reuse layouts and not the Activity source. +This is where Fragments come into play. + +Fragments +--------- +
![image](http://iontech.files.wordpress.com/2013/01/androidfragmentation1-264x300.png)
+Fragments encompass both layout resource and Java source. Hence, unlike ``, they allow us to reuse the View components along with their functionality, if needed. +Fragments were first introduced in Honeycomb(API 11), living under the `android.app` package. +**Note**: API 11 implies that Fragments have no support for devices less than Honeycomb and, for the record, as of writing this post, [more than 50% of Android devices worldwide run versions of Android below Honeycomb](http://developer.android.com/about/dashboards/index.html). Developer dissapointed? You don't have to be, cause google has been cautious enough to add the Fragment APIs to the support library. Yay! + +In the support library Fragment APIs sit in the `android.support.v4.app` package. This post assumes that your `minSdk` support is below API 11. Hence we concentrate on the Fragment APIs of the support library. + +### Diving into code + +Performing code reuse with Fragments involves three major steps: + +1. Creating reusable View components - Creating a layout for the fragment. +2. Creating reusable Java source - Writing the layout's corresponding Fragment class. +3. Employing the reusable components in Activity - Making an Activity to host this Fragment. + +#### 1. Creating reusable View components +##### Creating a layout for the Fragment +This is done precisely as we do it for our activity layouts. The layout contains a root element (ViewGroup) defining the layout, For instance in our example we use a LinearLayout and its child elements(the reusable Views) that we want to have in our fragment. + +> [fragment_common.xml](https://github.com/iontech/Fragments_Example/blob/master/res/layout/fragment_common.xml) + + + + + +