@produtype/core 1.16.0 → 1.17.1
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.
|
@@ -10,7 +10,21 @@ const valuesFromPackage_1 = require("./structural/valuesFromPackage");
|
|
|
10
10
|
const readingDepth_1 = require("./readingDepth");
|
|
11
11
|
const developmentOnly_1 = require("./developmentOnly");
|
|
12
12
|
/** Lines that decide which origins may call this server. */
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The header, spelled the way each language spells it.
|
|
15
|
+
*
|
|
16
|
+
* photoprism refers to its headers by the constants it declared for them —
|
|
17
|
+
* `c.Header(header.AccessControlAllowOrigin, header.Any)` in `start.go` and
|
|
18
|
+
* `static.go`, which is where it opens itself — and those lines carry no hyphens, so
|
|
19
|
+
* a pattern written as the wire name could not see any of them. Excluding the
|
|
20
|
+
* constant table without this took the project from a right verdict on the wrong
|
|
21
|
+
* evidence to no verdict at all, which is worse.
|
|
22
|
+
*
|
|
23
|
+
* The camel spelling is still the protocol's name: Go, Java and C# write
|
|
24
|
+
* `AccessControlAllowOrigin` because that is what their conventions do to
|
|
25
|
+
* `Access-Control-Allow-Origin`. It is not the author's word either way.
|
|
26
|
+
*/
|
|
27
|
+
const ORIGIN_HANDLING = [/Access-Control-Allow-Origin/i, /\bAccessControlAllowOrigin\b/, /ALLOWED_ORIGINS/, /allowedOrigins/i];
|
|
14
28
|
/** A header name used as a key into a headers object: a lookup, not a decision. */
|
|
15
29
|
const READS_A_HEADER = /\[\s*(['"`])[^'"`]+\1\s*\](?!\s*=[^=])/;
|
|
16
30
|
/** The calls that put one on a response, in the frameworks this reads. */
|
package/dist/utils/textSearch.js
CHANGED
|
@@ -26,6 +26,50 @@ const blockComments_1 = require("../analyzer/blockComments");
|
|
|
26
26
|
* and is left alone.
|
|
27
27
|
*/
|
|
28
28
|
const PATTERN_DECLARATION = /^(?:const\s+\w+(?:\s*:[^=]+)?\s*=\s*)?\/(?:[^/\\]|\\.)+\/[gimsuy]*\s*[,;]?$/;
|
|
29
|
+
/**
|
|
30
|
+
* A constant that spells its own name.
|
|
31
|
+
*
|
|
32
|
+
* photoprism keeps `AccessControlAllowOrigin = "Access-Control-Allow-Origin"` in
|
|
33
|
+
* `pkg/http/header/cors.go`, beside three more of the same, and that table was the
|
|
34
|
+
* whole evidence for its cross-origin finding — while
|
|
35
|
+
* `c.Header(header.AccessControlAllowOrigin, header.Any)` in `start.go` and
|
|
36
|
+
* `static.go`, the lines that actually open it, went uncited.
|
|
37
|
+
*
|
|
38
|
+
* A line whose value is its own identifier written out is a name for something, not a
|
|
39
|
+
* use of it. It is the third member of a family this file already has: a regex in a
|
|
40
|
+
* table is not a search, a name given a type is not a decision, and a header constant
|
|
41
|
+
* is not a header.
|
|
42
|
+
*
|
|
43
|
+
* Compared after normalising case and separators, because that is the only difference
|
|
44
|
+
* between the two halves — `ACCESS_CONTROL_ALLOW_ORIGIN`, `AccessControlAllowOrigin`
|
|
45
|
+
* and `"access-control-allow-origin"` are one string spelled three ways. A trailing
|
|
46
|
+
* comment is dropped first; Go puts the documentation link on the same line.
|
|
47
|
+
*/
|
|
48
|
+
/**
|
|
49
|
+
* A header name, in the shape the protocol writes them.
|
|
50
|
+
*
|
|
51
|
+
* Radarr shortens its constants — `public const string AllowOrigin =
|
|
52
|
+
* "Access-Control-Allow-Origin";` — so the two halves do not match and the
|
|
53
|
+
* spells-its-own-name test says nothing. It is the same table: five lines naming five
|
|
54
|
+
* headers, and the policy that matters is `builder.AllowAnyOrigin()` in `Startup.cs`,
|
|
55
|
+
* two files away.
|
|
56
|
+
*
|
|
57
|
+
* Hyphenated capitalised words are how HTTP writes a header and almost nothing else
|
|
58
|
+
* is written that way. It is required to be the whole value of a declaration, so a
|
|
59
|
+
* line that *sends* one — `res.setHeader('Access-Control-Allow-Origin', origin)` —
|
|
60
|
+
* has other arguments and is untouched.
|
|
61
|
+
*/
|
|
62
|
+
const HTTP_HEADER_NAME = /^[A-Z][A-Za-z0-9]*(?:-[A-Z][A-Za-z0-9]*)+$/;
|
|
63
|
+
function spellsItsOwnName(trimmed) {
|
|
64
|
+
const withoutComment = trimmed.replace(/\s*(\/\/|#).*$/, '').replace(/[,;]\s*$/, '');
|
|
65
|
+
const assignment = /^(?:(?:public|private|protected|internal|export|const|let|var|final|static|readonly|string)\s+)*([A-Za-z_][\w.]*)\s*(?::\s*[\w<>[\].]+)?\s*=\s*(['"`])([^'"`]+)\2$/.exec(withoutComment);
|
|
66
|
+
if (!assignment)
|
|
67
|
+
return false;
|
|
68
|
+
const plain = (value) => value.toLowerCase().replace(/[-_.\s]/g, '');
|
|
69
|
+
const declared = /^\s*(?:public|private|protected|internal|export|const|let|var|final|static|readonly)\b/.test(withoutComment);
|
|
70
|
+
return plain(assignment[1]) === plain(assignment[3])
|
|
71
|
+
|| (declared && HTTP_HEADER_NAME.test(assignment[3]));
|
|
72
|
+
}
|
|
29
73
|
/**
|
|
30
74
|
* A name given a type, rather than a value.
|
|
31
75
|
*
|
|
@@ -92,7 +136,7 @@ function declaresAType(trimmed) {
|
|
|
92
136
|
}
|
|
93
137
|
function declaresRatherThanDoes(line) {
|
|
94
138
|
const trimmed = line.trim();
|
|
95
|
-
return COMMENT_LINE.test(trimmed) || PATTERN_DECLARATION.test(trimmed) || declaresAType(trimmed);
|
|
139
|
+
return COMMENT_LINE.test(trimmed) || PATTERN_DECLARATION.test(trimmed) || declaresAType(trimmed) || spellsItsOwnName(trimmed);
|
|
96
140
|
}
|
|
97
141
|
/**
|
|
98
142
|
* Whether this line may be quoted back to the reader as something the code does.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@produtype/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.1",
|
|
4
4
|
"description": "Deterministic CLI and library that analyzes a web application repository and reports how far it is from production-ready for the kind of product it is meant to be.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|