~ubuntu-branches/ubuntu/saucy/mozjs17/saucy

« back to all changes in this revision

Viewing changes to js/src/tests/e4x/Regress/regress-350629.js

  • Committer: Package Import Robot
  • Author(s): Rico Tzschichholz
  • Date: 2013-05-25 12:24:23 UTC
  • Revision ID: package-import@ubuntu.com-20130525122423-zmxucrhtensw90xy
Tags: upstream-17.0.0
ImportĀ upstreamĀ versionĀ 17.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// |reftest| pref(javascript.options.xml.content,true)
 
2
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
3
/* This Source Code Form is subject to the terms of the Mozilla Public
 
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
6
 
 
7
 
 
8
//-----------------------------------------------------------------------------
 
9
var BUGNUMBER     = "350629";
 
10
var summary = ".toXMLString can include invalid generated prefixes";
 
11
var actual, expect;
 
12
 
 
13
printBugNumber(BUGNUMBER);
 
14
START(summary);
 
15
 
 
16
/**************
 
17
 * BEGIN TEST *
 
18
 **************/
 
19
 
 
20
var failed = false;
 
21
 
 
22
function extractPrefix(el, attrName, attrVal)
 
23
{
 
24
  var str = el.toXMLString();
 
25
  var regex = new RegExp(' (.+?):' + attrName + '="' + attrVal + '"');
 
26
  return str.match(regex)[1];
 
27
}
 
28
 
 
29
function assertValidPrefix(p, msg)
 
30
{
 
31
  if (!isXMLName(p) ||
 
32
      0 == p.search(/xml/i))
 
33
    throw msg;
 
34
}
 
35
 
 
36
var el, n, p;
 
37
 
 
38
try
 
39
{
 
40
  // last component is invalid prefix
 
41
  el = <foo/>;
 
42
  n = new Namespace("http://foo/bar.xml");
 
43
  el.@n::fiz = "eit";
 
44
  p = extractPrefix(el, "fiz", "eit");
 
45
  assertValidPrefix(p, "namespace " + n.uri + " generated invalid prefix " + p);
 
46
 
 
47
  // last component is invalid prefix (different case)
 
48
  el = <foo/>;
 
49
  n = new Namespace("http://foo/bar.XML");
 
50
  el.@n::fiz = "eit";
 
51
  p = extractPrefix(el, "fiz", "eit");
 
52
  assertValidPrefix(p, "namespace " + n.uri + " generated invalid prefix " + p);
 
53
 
 
54
  // last component is invalid prefix (but not "xml"/"xmlns")
 
55
  el = <foo/>;
 
56
  n = new Namespace("http://foo/bar.xmln");
 
57
  el.@n::baz = "quux";
 
58
  p = extractPrefix(el, "baz", "quux");
 
59
  assertValidPrefix(p, "namespace " + n.uri + " generated invalid prefix " + p);
 
60
 
 
61
 
 
62
  // generated prefix with no valid prefix component in namespace URI
 
63
  el = <foo/>;
 
64
  n = new Namespace("xml:///");
 
65
  el.@n::bike = "cycle";
 
66
  p = extractPrefix(el, "bike", "cycle");
 
67
  assertValidPrefix(p, "namespace " + n.uri + " generated invalid prefix " + p);
 
68
 
 
69
 
 
70
  // generated prefix with no valid prefix component in namespace URI w/further
 
71
  // collision
 
72
  el = <aaaaa:foo xmlns:aaaaa="http://baz/"/>;
 
73
  n = new Namespace("xml:///");
 
74
  el.@n::bike = "cycle";
 
75
  p = extractPrefix(el, "bike", "cycle");
 
76
  assertValidPrefix(p, "namespace " + n.uri + " generated invalid prefix " + p);
 
77
 
 
78
 
 
79
 
 
80
  // XXX this almost certainly shouldn't work, so if it fails at some time it
 
81
  //     might not be a bug!  it's only here because it *is* currently a
 
82
  //     possible failure point for prefix generation
 
83
  el = <foo/>;
 
84
  n = new Namespace(".:/.././.:/:");
 
85
  el.@n::biz = "17";
 
86
  p = extractPrefix(el, "biz", "17");
 
87
  assertValidPrefix(p, "namespace " + n.uri + " generated invalid prefix " + p);
 
88
}
 
89
catch (ex)
 
90
{
 
91
  failed = ex;
 
92
}
 
93
 
 
94
expect = false;
 
95
actual = failed;
 
96
 
 
97
TEST(1, expect, actual);