w3c-validate-html 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +41 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -154,14 +154,49 @@ function toList(v) {
154
154
  */
155
155
  function toSafeName(href) {
156
156
  var s = String(href || '');
157
+ var out = '';
158
+ var i;
159
+ var ch;
160
+
157
161
  s = s.replace(/^https?:\/\//i, '');
158
- s = s.replace(/[?#].*$/, '');
159
162
  s = s.replace(/\/+/g, '/');
160
- s = s.replace(/[^a-z0-9/._-]+/gi, '_');
161
- s = s.replace(/\//g, '_');
162
- if (!s) { s = 'index.html'; }
163
- if (!/\.html?$/i.test(s)) { s += '.html'; }
164
- return s;
163
+
164
+ /* convert url chars to filename safe chars without stripping query */
165
+ for (i = 0; i < s.length; i++) {
166
+ ch = s.charAt(i);
167
+
168
+ /* keep common safe chars */
169
+ if (/[a-z0-9]/i.test(ch) || ch === '/' || ch === '.' || ch === '_' || ch === '-') {
170
+ out += ch;
171
+ }
172
+ /* map separators to readable tokens */
173
+ else if (ch === '?') {
174
+ out += '__q__';
175
+ }
176
+ else if (ch === '&') {
177
+ out += '__and__';
178
+ }
179
+ else if (ch === '=') {
180
+ out += '__eq__';
181
+ }
182
+ else if (ch === '#') {
183
+ out += '__hash__';
184
+ }
185
+ /* everything else becomes underscore */
186
+ else {
187
+ out += '_';
188
+ }
189
+ }
190
+
191
+ out = out.replace(/\/+/g, '/');
192
+ out = out.replace(/_+/g, '_');
193
+ out = out.replace(/\//g, '_');
194
+ out = out.replace(/^_+|_+$/g, '');
195
+
196
+ if (!out) { out = 'index.html'; }
197
+ if (!/\.html?$/i.test(out)) { out += '.html'; }
198
+
199
+ return out;
165
200
  }
166
201
 
167
202
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "w3c-validate-html",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Validate HTML offline using the official W3C vnu.jar",
5
5
  "type": "commonjs",
6
6
  "main": "index.js",