trusty-cms 5.0.6 → 5.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +60 -59
  3. data/app/models/asset.rb +8 -2
  4. data/app/views/admin/assets/_asset_table.html.haml +1 -1
  5. data/app/views/admin/assets/_search.html.haml +1 -1
  6. data/app/views/admin/assets/_search_results.html.haml +2 -2
  7. data/app/views/admin/assets/edit.html.haml +5 -5
  8. data/app/views/admin/assets/index.html.haml +1 -1
  9. data/app/views/admin/configuration/_clipped_show.html.haml +1 -1
  10. data/app/views/admin/pages/_asset_popups.html.haml +5 -5
  11. data/app/views/admin/removed/_assets_bucket.html.haml +2 -2
  12. data/app/views/admin/removed/_assets_container.html.haml +6 -6
  13. data/app/views/admin/removed/_bucket.html.haml +1 -1
  14. data/app/views/admin/removed/_upload_to_page.html.haml +1 -1
  15. data/app/views/admin/sites/_form.haml +2 -2
  16. data/app/views/admin/snippets/edit.html.haml +1 -1
  17. data/app/views/admin/snippets/new.html.haml +1 -1
  18. data/config/database.yml +4 -0
  19. data/coverage/index.html +154 -154
  20. data/lib/generators/extension_controller/templates/view_spec.rb +1 -1
  21. data/lib/generators/generator_base_extension.rb +0 -1
  22. data/lib/generators/instance/instance_generator.rb +1 -1
  23. data/lib/generators/language_extension/language_extension_generator.rb +0 -1
  24. data/lib/generators/language_extension/templates/test_helper.rb +0 -1
  25. data/lib/generators/trusty_cms/trusty_cms_generator.rb +0 -2
  26. data/lib/trusty_cms.rb +1 -1
  27. data/node_modules/ajv/README.md +158 -72
  28. data/node_modules/ajv/dist/ajv.bundle.js +136 -112
  29. data/node_modules/ajv/dist/ajv.min.js +2 -2
  30. data/node_modules/ajv/dist/ajv.min.js.map +1 -1
  31. data/node_modules/ajv/lib/ajv.d.ts +3 -1
  32. data/node_modules/ajv/lib/compile/equal.js +1 -1
  33. data/node_modules/ajv/lib/compile/formats.js +4 -4
  34. data/node_modules/ajv/lib/compile/index.js +1 -1
  35. data/node_modules/ajv/lib/compile/util.js +9 -44
  36. data/node_modules/ajv/lib/data.js +1 -1
  37. data/node_modules/ajv/lib/definition_schema.js +1 -1
  38. data/node_modules/ajv/lib/dot/_limit.jst +9 -0
  39. data/node_modules/ajv/lib/dot/_limitItems.jst +2 -0
  40. data/node_modules/ajv/lib/dot/_limitLength.jst +2 -0
  41. data/node_modules/ajv/lib/dot/_limitProperties.jst +2 -0
  42. data/node_modules/ajv/lib/dot/allOf.jst +0 -2
  43. data/node_modules/ajv/lib/dot/anyOf.jst +0 -2
  44. data/node_modules/ajv/lib/dot/coerce.def +18 -28
  45. data/node_modules/ajv/lib/dot/contains.jst +0 -2
  46. data/node_modules/ajv/lib/dot/definitions.def +9 -7
  47. data/node_modules/ajv/lib/dot/dependencies.jst +1 -2
  48. data/node_modules/ajv/lib/dot/if.jst +0 -2
  49. data/node_modules/ajv/lib/dot/items.jst +0 -2
  50. data/node_modules/ajv/lib/dot/multipleOf.jst +2 -0
  51. data/node_modules/ajv/lib/dot/properties.jst +6 -5
  52. data/node_modules/ajv/lib/dot/propertyNames.jst +0 -2
  53. data/node_modules/ajv/lib/dot/uniqueItems.jst +1 -1
  54. data/node_modules/ajv/lib/dot/validate.jst +3 -9
  55. data/node_modules/ajv/lib/dotjs/_limit.js +6 -0
  56. data/node_modules/ajv/lib/dotjs/_limitItems.js +3 -0
  57. data/node_modules/ajv/lib/dotjs/_limitLength.js +3 -0
  58. data/node_modules/ajv/lib/dotjs/_limitProperties.js +3 -0
  59. data/node_modules/ajv/lib/dotjs/allOf.js +1 -2
  60. data/node_modules/ajv/lib/dotjs/anyOf.js +1 -2
  61. data/node_modules/ajv/lib/dotjs/contains.js +1 -2
  62. data/node_modules/ajv/lib/dotjs/dependencies.js +2 -2
  63. data/node_modules/ajv/lib/dotjs/if.js +2 -3
  64. data/node_modules/ajv/lib/dotjs/items.js +3 -4
  65. data/node_modules/ajv/lib/dotjs/multipleOf.js +3 -0
  66. data/node_modules/ajv/lib/dotjs/not.js +1 -1
  67. data/node_modules/ajv/lib/dotjs/oneOf.js +1 -1
  68. data/node_modules/ajv/lib/dotjs/properties.js +11 -6
  69. data/node_modules/ajv/lib/dotjs/propertyNames.js +1 -2
  70. data/node_modules/ajv/lib/dotjs/required.js +1 -1
  71. data/node_modules/ajv/lib/dotjs/uniqueItems.js +1 -1
  72. data/node_modules/ajv/lib/dotjs/validate.js +13 -25
  73. data/node_modules/ajv/lib/keyword.js +1 -1
  74. data/node_modules/ajv/lib/refs/data.json +1 -1
  75. data/node_modules/ajv/lib/refs/json-schema-secure.json +1 -1
  76. data/node_modules/ajv/package.json +18 -10
  77. data/node_modules/ajv/scripts/info +0 -0
  78. data/node_modules/ajv/scripts/prepare-tests +0 -0
  79. data/node_modules/ajv/scripts/publish-built-version +1 -1
  80. data/node_modules/ajv/scripts/travis-gh-pages +1 -1
  81. data/node_modules/fast-deep-equal/es6/index.d.ts +1 -1
  82. data/node_modules/fast-deep-equal/es6/react.d.ts +1 -1
  83. data/node_modules/fast-deep-equal/package.json +7 -7
  84. data/node_modules/fast-deep-equal/react.d.ts +1 -1
  85. data/node_modules/uri-js/LICENSE +11 -0
  86. data/node_modules/uri-js/README.md +22 -18
  87. data/node_modules/uri-js/dist/es5/uri.all.d.ts +59 -59
  88. data/node_modules/uri-js/dist/es5/uri.all.js +61 -7
  89. data/node_modules/uri-js/dist/es5/uri.all.js.map +1 -1
  90. data/node_modules/uri-js/dist/es5/uri.all.min.d.ts +59 -59
  91. data/node_modules/uri-js/dist/es5/uri.all.min.js +2 -2
  92. data/node_modules/uri-js/dist/es5/uri.all.min.js.map +1 -1
  93. data/node_modules/uri-js/dist/esnext/index.d.ts +1 -1
  94. data/node_modules/uri-js/dist/esnext/index.js +16 -12
  95. data/node_modules/uri-js/dist/esnext/index.js.map +1 -1
  96. data/node_modules/uri-js/dist/esnext/regexps-iri.d.ts +3 -3
  97. data/node_modules/uri-js/dist/esnext/regexps-iri.js +2 -2
  98. data/node_modules/uri-js/dist/esnext/regexps-iri.js.map +0 -0
  99. data/node_modules/uri-js/dist/esnext/regexps-uri.d.ts +4 -4
  100. data/node_modules/uri-js/dist/esnext/regexps-uri.js +41 -41
  101. data/node_modules/uri-js/dist/esnext/regexps-uri.js.map +0 -0
  102. data/node_modules/uri-js/dist/esnext/schemes/http.d.ts +3 -3
  103. data/node_modules/uri-js/dist/esnext/schemes/http.js +27 -26
  104. data/node_modules/uri-js/dist/esnext/schemes/http.js.map +1 -1
  105. data/node_modules/uri-js/dist/esnext/schemes/https.d.ts +3 -3
  106. data/node_modules/uri-js/dist/esnext/schemes/https.js +8 -8
  107. data/node_modules/uri-js/dist/esnext/schemes/https.js.map +0 -0
  108. data/node_modules/uri-js/dist/esnext/schemes/mailto.d.ts +12 -12
  109. data/node_modules/uri-js/dist/esnext/schemes/mailto.js +0 -0
  110. data/node_modules/uri-js/dist/esnext/schemes/mailto.js.map +0 -0
  111. data/node_modules/uri-js/dist/esnext/schemes/urn-uuid.d.ts +7 -7
  112. data/node_modules/uri-js/dist/esnext/schemes/urn-uuid.js +22 -22
  113. data/node_modules/uri-js/dist/esnext/schemes/urn-uuid.js.map +0 -0
  114. data/node_modules/uri-js/dist/esnext/schemes/urn.d.ts +10 -10
  115. data/node_modules/uri-js/dist/esnext/schemes/urn.js +48 -48
  116. data/node_modules/uri-js/dist/esnext/schemes/urn.js.map +0 -0
  117. data/node_modules/uri-js/dist/esnext/schemes/ws.d.ts +7 -0
  118. data/node_modules/uri-js/dist/esnext/schemes/ws.js +41 -0
  119. data/node_modules/uri-js/dist/esnext/schemes/ws.js.map +1 -0
  120. data/node_modules/uri-js/dist/esnext/schemes/wss.d.ts +3 -0
  121. data/node_modules/uri-js/dist/esnext/schemes/wss.js +9 -0
  122. data/node_modules/uri-js/dist/esnext/schemes/wss.js.map +1 -0
  123. data/node_modules/uri-js/dist/esnext/uri.d.ts +59 -59
  124. data/node_modules/uri-js/dist/esnext/uri.js +2 -2
  125. data/node_modules/uri-js/dist/esnext/uri.js.map +1 -1
  126. data/node_modules/uri-js/dist/esnext/util.d.ts +6 -6
  127. data/node_modules/uri-js/dist/esnext/util.js +35 -35
  128. data/node_modules/uri-js/dist/esnext/util.js.map +0 -0
  129. data/node_modules/uri-js/package.json +19 -7
  130. data/node_modules/uri-js/yarn.lock +1271 -615
  131. data/spec/dummy/log/test.log +635 -0
  132. data/spec/dummy/tmp/cache/747/A70/TrustyCms%3A%3AConfig +0 -0
  133. data/spec/dummy/tmp/cache/85C/FA0/TrustyCms.cache_mtime +1 -0
  134. data/trusty_cms.gemspec +2 -1
  135. data/yarn.lock +9 -9
  136. metadata +48 -57
  137. data/node_modules/uri-js/bower.json +0 -47
  138. data/node_modules/uri-js/rollup.config.js +0 -32
  139. data/node_modules/uri-js/src/index.ts +0 -18
  140. data/node_modules/uri-js/src/punycode.d.ts +0 -24
  141. data/node_modules/uri-js/src/regexps-iri.ts +0 -4
  142. data/node_modules/uri-js/src/regexps-uri.ts +0 -89
  143. data/node_modules/uri-js/src/schemes/http.ts +0 -36
  144. data/node_modules/uri-js/src/schemes/https.ts +0 -11
  145. data/node_modules/uri-js/src/schemes/mailto.ts +0 -182
  146. data/node_modules/uri-js/src/schemes/urn-uuid.ts +0 -36
  147. data/node_modules/uri-js/src/schemes/urn.ts +0 -69
  148. data/node_modules/uri-js/src/uri.ts +0 -556
  149. data/node_modules/uri-js/src/util.ts +0 -40
  150. data/node_modules/uri-js/tests/qunit.css +0 -118
  151. data/node_modules/uri-js/tests/qunit.js +0 -1042
  152. data/node_modules/uri-js/tests/test-es5-min.html +0 -17
  153. data/node_modules/uri-js/tests/test-es5.html +0 -17
  154. data/node_modules/uri-js/tests/tests.js +0 -774
  155. data/node_modules/uri-js/tsconfig.json +0 -20
  156. data/spec/dummy/log/development.log +0 -456
@@ -1,182 +0,0 @@
1
- import { URISchemeHandler, URIComponents, URIOptions } from "../uri";
2
- import { pctEncChar, pctDecChars, unescapeComponent } from "../uri";
3
- import punycode from "punycode";
4
- import { merge, subexp, toUpperCase, toArray } from "../util";
5
-
6
- export interface MailtoHeaders {
7
- [hfname:string]:string
8
- }
9
-
10
- export interface MailtoComponents extends URIComponents {
11
- to:Array<string>,
12
- headers?:MailtoHeaders,
13
- subject?:string,
14
- body?:string
15
- }
16
-
17
- const O:MailtoHeaders = {};
18
- const isIRI = true;
19
-
20
- //RFC 3986
21
- const UNRESERVED$$ = "[A-Za-z0-9\\-\\.\\_\\~" + (isIRI ? "\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF" : "") + "]";
22
- const HEXDIG$$ = "[0-9A-Fa-f]"; //case-insensitive
23
- const PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)); //expanded
24
-
25
- //RFC 5322, except these symbols as per RFC 6068: @ : / ? # [ ] & ; =
26
- //const ATEXT$$ = "[A-Za-z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]";
27
- //const WSP$$ = "[\\x20\\x09]";
28
- //const OBS_QTEXT$$ = "[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]"; //(%d1-8 / %d11-12 / %d14-31 / %d127)
29
- //const QTEXT$$ = merge("[\\x21\\x23-\\x5B\\x5D-\\x7E]", OBS_QTEXT$$); //%d33 / %d35-91 / %d93-126 / obs-qtext
30
- //const VCHAR$$ = "[\\x21-\\x7E]";
31
- //const WSP$$ = "[\\x20\\x09]";
32
- //const OBS_QP$ = subexp("\\\\" + merge("[\\x00\\x0D\\x0A]", OBS_QTEXT$$)); //%d0 / CR / LF / obs-qtext
33
- //const FWS$ = subexp(subexp(WSP$$ + "*" + "\\x0D\\x0A") + "?" + WSP$$ + "+");
34
- //const QUOTED_PAIR$ = subexp(subexp("\\\\" + subexp(VCHAR$$ + "|" + WSP$$)) + "|" + OBS_QP$);
35
- //const QUOTED_STRING$ = subexp('\\"' + subexp(FWS$ + "?" + QCONTENT$) + "*" + FWS$ + "?" + '\\"');
36
- const ATEXT$$ = "[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]";
37
- const QTEXT$$ = "[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]";
38
- const VCHAR$$ = merge(QTEXT$$, "[\\\"\\\\]");
39
- const DOT_ATOM_TEXT$ = subexp(ATEXT$$ + "+" + subexp("\\." + ATEXT$$ + "+") + "*");
40
- const QUOTED_PAIR$ = subexp("\\\\" + VCHAR$$);
41
- const QCONTENT$ = subexp(QTEXT$$ + "|" + QUOTED_PAIR$);
42
- const QUOTED_STRING$ = subexp('\\"' + QCONTENT$ + "*" + '\\"');
43
-
44
- //RFC 6068
45
- const DTEXT_NO_OBS$$ = "[\\x21-\\x5A\\x5E-\\x7E]"; //%d33-90 / %d94-126
46
- const SOME_DELIMS$$ = "[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]";
47
- const QCHAR$ = subexp(UNRESERVED$$ + "|" + PCT_ENCODED$ + "|" + SOME_DELIMS$$);
48
- const DOMAIN$ = subexp(DOT_ATOM_TEXT$ + "|" + "\\[" + DTEXT_NO_OBS$$ + "*" + "\\]");
49
- const LOCAL_PART$ = subexp(DOT_ATOM_TEXT$ + "|" + QUOTED_STRING$);
50
- const ADDR_SPEC$ = subexp(LOCAL_PART$ + "\\@" + DOMAIN$);
51
- const TO$ = subexp(ADDR_SPEC$ + subexp("\\," + ADDR_SPEC$) + "*");
52
- const HFNAME$ = subexp(QCHAR$ + "*");
53
- const HFVALUE$ = HFNAME$;
54
- const HFIELD$ = subexp(HFNAME$ + "\\=" + HFVALUE$);
55
- const HFIELDS2$ = subexp(HFIELD$ + subexp("\\&" + HFIELD$) + "*");
56
- const HFIELDS$ = subexp("\\?" + HFIELDS2$);
57
- const MAILTO_URI = new RegExp("^mailto\\:" + TO$ + "?" + HFIELDS$ + "?$");
58
-
59
- const UNRESERVED = new RegExp(UNRESERVED$$, "g");
60
- const PCT_ENCODED = new RegExp(PCT_ENCODED$, "g");
61
- const NOT_LOCAL_PART = new RegExp(merge("[^]", ATEXT$$, "[\\.]", '[\\"]', VCHAR$$), "g");
62
- const NOT_DOMAIN = new RegExp(merge("[^]", ATEXT$$, "[\\.]", "[\\[]", DTEXT_NO_OBS$$, "[\\]]"), "g");
63
- const NOT_HFNAME = new RegExp(merge("[^]", UNRESERVED$$, SOME_DELIMS$$), "g");
64
- const NOT_HFVALUE = NOT_HFNAME;
65
- const TO = new RegExp("^" + TO$ + "$");
66
- const HFIELDS = new RegExp("^" + HFIELDS2$ + "$");
67
-
68
- function decodeUnreserved(str:string):string {
69
- const decStr = pctDecChars(str);
70
- return (!decStr.match(UNRESERVED) ? str : decStr);
71
- }
72
-
73
- const handler:URISchemeHandler<MailtoComponents> = {
74
- scheme : "mailto",
75
-
76
- parse : function (components:URIComponents, options:URIOptions):MailtoComponents {
77
- const mailtoComponents = components as MailtoComponents;
78
- const to = mailtoComponents.to = (mailtoComponents.path ? mailtoComponents.path.split(",") : []);
79
- mailtoComponents.path = undefined;
80
-
81
- if (mailtoComponents.query) {
82
- let unknownHeaders = false
83
- const headers:MailtoHeaders = {};
84
- const hfields = mailtoComponents.query.split("&");
85
-
86
- for (let x = 0, xl = hfields.length; x < xl; ++x) {
87
- const hfield = hfields[x].split("=");
88
-
89
- switch (hfield[0]) {
90
- case "to":
91
- const toAddrs = hfield[1].split(",");
92
- for (let x = 0, xl = toAddrs.length; x < xl; ++x) {
93
- to.push(toAddrs[x]);
94
- }
95
- break;
96
- case "subject":
97
- mailtoComponents.subject = unescapeComponent(hfield[1], options);
98
- break;
99
- case "body":
100
- mailtoComponents.body = unescapeComponent(hfield[1], options);
101
- break;
102
- default:
103
- unknownHeaders = true;
104
- headers[unescapeComponent(hfield[0], options)] = unescapeComponent(hfield[1], options);
105
- break;
106
- }
107
- }
108
-
109
- if (unknownHeaders) mailtoComponents.headers = headers;
110
- }
111
-
112
- mailtoComponents.query = undefined;
113
-
114
- for (let x = 0, xl = to.length; x < xl; ++x) {
115
- const addr = to[x].split("@");
116
-
117
- addr[0] = unescapeComponent(addr[0]);
118
-
119
- if (!options.unicodeSupport) {
120
- //convert Unicode IDN -> ASCII IDN
121
- try {
122
- addr[1] = punycode.toASCII(unescapeComponent(addr[1], options).toLowerCase());
123
- } catch (e) {
124
- mailtoComponents.error = mailtoComponents.error || "Email address's domain name can not be converted to ASCII via punycode: " + e;
125
- }
126
- } else {
127
- addr[1] = unescapeComponent(addr[1], options).toLowerCase();
128
- }
129
-
130
- to[x] = addr.join("@");
131
- }
132
-
133
- return mailtoComponents;
134
- },
135
-
136
- serialize : function (mailtoComponents:MailtoComponents, options:URIOptions):URIComponents {
137
- const components = mailtoComponents as URIComponents;
138
- const to = toArray(mailtoComponents.to);
139
- if (to) {
140
- for (let x = 0, xl = to.length; x < xl; ++x) {
141
- const toAddr = String(to[x]);
142
- const atIdx = toAddr.lastIndexOf("@");
143
- const localPart = (toAddr.slice(0, atIdx)).replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_LOCAL_PART, pctEncChar);
144
- let domain = toAddr.slice(atIdx + 1);
145
-
146
- //convert IDN via punycode
147
- try {
148
- domain = (!options.iri ? punycode.toASCII(unescapeComponent(domain, options).toLowerCase()) : punycode.toUnicode(domain));
149
- } catch (e) {
150
- components.error = components.error || "Email address's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
151
- }
152
-
153
- to[x] = localPart + "@" + domain;
154
- }
155
-
156
- components.path = to.join(",");
157
- }
158
-
159
- const headers = mailtoComponents.headers = mailtoComponents.headers || {};
160
-
161
- if (mailtoComponents.subject) headers["subject"] = mailtoComponents.subject;
162
- if (mailtoComponents.body) headers["body"] = mailtoComponents.body;
163
-
164
- const fields = [];
165
- for (const name in headers) {
166
- if (headers[name] !== O[name]) {
167
- fields.push(
168
- name.replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_HFNAME, pctEncChar) +
169
- "=" +
170
- headers[name].replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_HFVALUE, pctEncChar)
171
- );
172
- }
173
- }
174
- if (fields.length) {
175
- components.query = fields.join("&");
176
- }
177
-
178
- return components;
179
- }
180
- }
181
-
182
- export default handler;
@@ -1,36 +0,0 @@
1
- import { URISchemeHandler, URIComponents, URIOptions } from "../uri";
2
- import { URNComponents } from "./urn";
3
- import { SCHEMES } from "../uri";
4
-
5
- export interface UUIDComponents extends URNComponents {
6
- uuid?: string;
7
- }
8
-
9
- const UUID = /^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/;
10
- const UUID_PARSE = /^[0-9A-Fa-f\-]{36}/;
11
-
12
- //RFC 4122
13
- const handler:URISchemeHandler<UUIDComponents, URIOptions, URNComponents> = {
14
- scheme : "urn:uuid",
15
-
16
- parse : function (urnComponents:URNComponents, options:URIOptions):UUIDComponents {
17
- const uuidComponents = urnComponents as UUIDComponents;
18
- uuidComponents.uuid = uuidComponents.nss;
19
- uuidComponents.nss = undefined;
20
-
21
- if (!options.tolerant && (!uuidComponents.uuid || !uuidComponents.uuid.match(UUID))) {
22
- uuidComponents.error = uuidComponents.error || "UUID is not valid.";
23
- }
24
-
25
- return uuidComponents;
26
- },
27
-
28
- serialize : function (uuidComponents:UUIDComponents, options:URIOptions):URNComponents {
29
- const urnComponents = uuidComponents as URNComponents;
30
- //normalize UUID
31
- urnComponents.nss = (uuidComponents.uuid || "").toLowerCase();
32
- return urnComponents;
33
- },
34
- };
35
-
36
- export default handler;
@@ -1,69 +0,0 @@
1
- import { URISchemeHandler, URIComponents, URIOptions } from "../uri";
2
- import { pctEncChar, SCHEMES } from "../uri";
3
-
4
- export interface URNComponents extends URIComponents {
5
- nid?:string;
6
- nss?:string;
7
- }
8
-
9
- export interface URNOptions extends URIOptions {
10
- nid?:string;
11
- }
12
-
13
- const NID$ = "(?:[0-9A-Za-z][0-9A-Za-z\\-]{1,31})";
14
- const PCT_ENCODED$ = "(?:\\%[0-9A-Fa-f]{2})";
15
- const TRANS$$ = "[0-9A-Za-z\\(\\)\\+\\,\\-\\.\\:\\=\\@\\;\\$\\_\\!\\*\\'\\/\\?\\#]";
16
- const NSS$ = "(?:(?:" + PCT_ENCODED$ + "|" + TRANS$$ + ")+)";
17
- const URN_SCHEME = new RegExp("^urn\\:(" + NID$ + ")$");
18
- const URN_PATH = new RegExp("^(" + NID$ + ")\\:(" + NSS$ + ")$");
19
- const URN_PARSE = /^([^\:]+)\:(.*)/;
20
- const URN_EXCLUDED = /[\x00-\x20\\\"\&\<\>\[\]\^\`\{\|\}\~\x7F-\xFF]/g;
21
-
22
- //RFC 2141
23
- const handler:URISchemeHandler<URNComponents,URNOptions> = {
24
- scheme : "urn",
25
-
26
- parse : function (components:URIComponents, options:URNOptions):URNComponents {
27
- const matches = components.path && components.path.match(URN_PARSE);
28
- let urnComponents = components as URNComponents;
29
-
30
- if (matches) {
31
- const scheme = options.scheme || urnComponents.scheme || "urn";
32
- const nid = matches[1].toLowerCase();
33
- const nss = matches[2];
34
- const urnScheme = `${scheme}:${options.nid || nid}`;
35
- const schemeHandler = SCHEMES[urnScheme];
36
-
37
- urnComponents.nid = nid;
38
- urnComponents.nss = nss;
39
- urnComponents.path = undefined;
40
-
41
- if (schemeHandler) {
42
- urnComponents = schemeHandler.parse(urnComponents, options) as URNComponents;
43
- }
44
- } else {
45
- urnComponents.error = urnComponents.error || "URN can not be parsed.";
46
- }
47
-
48
- return urnComponents;
49
- },
50
-
51
- serialize : function (urnComponents:URNComponents, options:URNOptions):URIComponents {
52
- const scheme = options.scheme || urnComponents.scheme || "urn";
53
- const nid = urnComponents.nid;
54
- const urnScheme = `${scheme}:${options.nid || nid}`;
55
- const schemeHandler = SCHEMES[urnScheme];
56
-
57
- if (schemeHandler) {
58
- urnComponents = schemeHandler.serialize(urnComponents, options) as URNComponents;
59
- }
60
-
61
- const uriComponents = urnComponents as URIComponents;
62
- const nss = urnComponents.nss;
63
- uriComponents.path = `${nid || options.nid}:${nss}`;
64
-
65
- return uriComponents;
66
- },
67
- };
68
-
69
- export default handler;