Escape any special tags so that they won't be interpreted by the label.
335483
public static String escapeColors (String txt)
    {
        if (txt == null) return null;
        return COLOR_PATTERN.matcher(txt).replaceAll("#''$1");
    }
514385
def sanitize_allow(value, args=''):
    '''
    
    '''
    if isinstance(value, basestring):
        allowed_tags = []
        allowed_attributes = []
        allowed_styles = []
        
        args = args.strip().split(';')
        if len(args) > 0:
            allowed_tags = [tag.strip() for tag in args[0].split(',')]
        if len(args) > 1:
            allowed_attributes = [attr.strip() for attr in args[1].split(',')]
            
        value = bleach.clean(value, tags=allowed_tags,
                             attributes=allowed_attributes, strip=True)
    return value
1136431
def removeHtmlTags(self, text):
		""""""
		sb = []
		text = self.removeHtmlComments(text)
		bits = text.split(u'<')
		sb.append(bits.pop(0))
		tagstack = []
		tablestack = tagstack
		for x in bits:
			m = _tagPattern.match(x)
			if not m:
				continue
			slash, t, params, brace, rest = m.groups()
			t = t.lower()
			badtag = False
			if t in _htmlelements:
				# Check our stack
				if slash:
					# Closing a tag...
					if t in _htmlsingleonly or len(tagstack) == 0:
						badtag = True
					else:
						ot = tagstack.pop()
						if ot != t:
							if ot in _htmlsingleallowed:
								# Pop all elements with an optional close tag
								# and see if we find a match below them
								optstack = []
								optstack.append(ot)
								while True:
									if len(tagstack) == 0:
										break
									ot = tagstack.pop()
									if ot == t or ot not in _htmlsingleallowed:
										break
									optstack.append(ot)
								if t != ot:
									# No match. Push the optinal elements back again
									badtag = True
									tagstack += reversed(optstack)
							else:
								tagstack.append(ot)
								# <li> can be nested in <ul> or <ol>, skip those cases:
								if ot not in _htmllist and t in _listtags:
									badtag = True
						elif t == u'table':
							if len(tablestack) == 0:
								bagtag = True
							else:
								tagstack = tablestack.pop()
					newparams = u''
				else:
					# Keep track for later
					if t in _tabletags and u'table' not in tagstack:
						badtag = True
					elif t in tagstack and t not in _htmlnest:
						badtag = True
					# Is it a self-closed htmlpair? (bug 5487)
					elif brace == u'/>' and t in _htmlpairs:
						badTag = True
					elif t in _htmlsingleonly:
						# Hack to force empty tag for uncloseable elements
						brace = u'/>'
					elif t in _htmlsingle:
						# Hack to not close $htmlsingle tags
						brace = None
					else:
						if t == u'table':
							tablestack.append(tagstack)
							tagstack = []
						tagstack.append(t)
					newparams = self.fixTagAttributes(params, t)
				if not badtag:
					rest = rest.replace(u'>', u'&gt;')
					if brace == u'/>':
						close = u' /'
					else:
						close = u''
					sb.append(u'<')
					sb.append(slash)
					sb.append(t)
					sb.append(newparams)
					sb.append(close)
					sb.append(u'>')
					sb.append(rest)
					continue
			sb.append(u'&lt;')
			sb.append(x.replace(u'>', u'&gt;'))

		# Close off any remaining tags
		while tagstack:
			t = tagstack.pop()
			sb.append(u'</')
			sb.append(t)
			sb.append(u'>\n')
			if t == u'table':
				if not tablestack:
					break
				tagstack = tablestack.pop()

		return u''.join(sb)
106193
def remove_markup (s):
    """"""
    mo = _markup_re.search(s)
    while mo:
        s = s[0:mo.start()] + s[mo.end():]
        mo = _markup_re.search(s)
    return s
1294277
def _escape(self, text):
        """"""
        ret = EMPTYSTRING if text is None else str(text)
        if self.escape:
            return html_escape(ret)
        else:
            return ret
1279932
def strip_tags(s):
    """"""

    def handle_match(m):
        name = m.group(1)
        if name in html_entities:
            return unichr(html_entities[name])
        if name[:2] in ("#x", "#X"):
            try:
                return unichr(int(name[2:], 16))
            except ValueError:
                return u""
        elif name.startswith("#"):
            try:
                return unichr(int(name[1:]))
            except ValueError:
                return u""
        return u""

    return _entity_re.sub(handle_match, _striptags_re.sub("", s))
874461
private String cleanTags(String s) {
    int idx = s.indexOf("#");
    if (idx != -1) {
      s = s.substring(0, idx);
    }
    return s.trim();
  }
153136
def Escape(self, string="", **_):
    """"""
    # Translate special escapes:
    self.stack[-1] += self.STRING_ESCAPES.get(string, string)
402366
def prettyhtml(value, autoescape=None):
	''
	value = html_cleaner(value)
	return escape(value) if autoescape\
		and not isinstance(value, SafeData) else mark_safe(value)
745154
def do_striptags(value):
    
    if hasattr(value, '__html__'):
        value = value.__html__()
    return Markup(text_type(value)).striptags()
484803
def strip_outer_tag(text):
    """"""
    if not text or not isinstance(text, basestring):
        return text
    stripped = text.strip()
    if (stripped.startswith('<p>') or stripped.startswith('<div>')) and \
        (stripped.endswith('</p>') or stripped.endswith('</div>')):
        return stripped[stripped.index('>')+1:stripped.rindex('<')]
    return text
528307
function detectEncoding(label, input_stream) {
      if (input_stream.match([0xFF, 0xFE])) {
        input_stream.offset(2);
        return 'utf-16';
      }
      if (input_stream.match([0xFE, 0xFF])) {
        input_stream.offset(2);
        return 'utf-16be';
      }
      if (input_stream.match([0xEF, 0xBB, 0xBF])) {
        input_stream.offset(3);
        return 'utf-8';
      }
      return label;
    }
952371
def sanitize(string, ignore_characters=None):
    
    # only deal with strings
    if string is None:
        return

    ignore_characters = ignore_characters or set()

    # replace some characters with one space
    characters = {'-', ':', '(', ')', '.'} - ignore_characters
    if characters:
        string = re.sub(r'[%s]' % re.escape(''.join(characters)), ' ', string)

    # remove some characters
    characters = {'\''} - ignore_characters
    if characters:
        string = re.sub(r'[%s]' % re.escape(''.join(characters)), '', string)

    # replace multiple spaces with one
    string = re.sub(r'\s+', ' ', string)

    # strip and lower case
    return string.strip().lower()
464904
private function escapeSpecTags($value): string
    {
        if ($this->black_tag_list) {
            SpecTags::addBlackList($this->black_tag_list);
        } elseif ($this->white_tag_list) {
            SpecTags::addWhiteList($this->white_tag_list);
        }

        return SpecTags::escape($value);
    }
1140905
def sanitize content  #:nodoc:
      if content.is_a? String
        content.chomp!
        # 2013-03-20 - 18:29 187compat
        if content.respond_to? :encode
          content.replace(content.encode("ASCII-8BIT", :invalid => :replace, :undef => :replace, :replace => "?"))
        end
        content.gsub!(/[\t\r\n]/, '  ') # don't display tab, newline
        content.gsub!(/\n/, '  ') # don't display tab, newline
        content.gsub!(/[^[:print:]]/, '')  # don't display non print characters
      else
        content
      end
    end
868526
def escape(s)
      s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) {
        '%'+$1.unpack('H2'*bytesize($1)).join('%').upcase
      }.tr(' ', '+')
    end
1202840
private static void escape(final String label, final StringBuilder builder) {
        final int length = label.length();
        for (int i = 0; i < length; ++i) {
            final char c = label.charAt(i);
            if (c == '\\') {
                builder.append("\\\\");
            } else if (c == '"') {
                builder.append("\\\"");
            } else if (c == '\n') {
                builder.append("\\n");
            } else if (c == '\r') {
                builder.append("\\r");
            } else if (c == '\t') {
                builder.append("\\t");
            }
            // TODO: not accepted by Virtuoso :-(
            // else if (c >= 0x0 && c <= 0x8 || c == 0xB || c == 0xC || c >= 0xE && c <= 0x1F
            // || c >= 0x7F && c <= 0xFFFF) {
            // builder.append("\\u").append(
            // Strings.padStart(Integer.toHexString(c).toUpperCase(), 4, '0'));
            // } else if (c >= 0x10000 && c <= 0x10FFFF) {
            // builder.append("\\U").append(
            // Strings.padStart(Integer.toHexString(c).toUpperCase(), 8, '0'));
            // }
            else {
                builder.append(Character.toString(c));
            }
        }
    }