Validate value types returned by API against expectations

This commit is contained in:
Michael B. Gale
2026-03-09 12:46:16 +00:00
parent 9c75a5f60c
commit 58991590bd
3 changed files with 98 additions and 36 deletions
+28 -14
View File
@@ -100091,7 +100091,7 @@ var require_follow_redirects = __commonJS({
if (this._ending) {
throw new WriteAfterEndError();
}
if (!isString(data) && !isBuffer(data)) {
if (!isString2(data) && !isBuffer(data)) {
throw new TypeError("data should be a string, Buffer or Uint8Array");
}
if (isFunction(encoding)) {
@@ -100346,7 +100346,7 @@ var require_follow_redirects = __commonJS({
function request2(input, options, callback) {
if (isURL(input)) {
input = spreadUrlObject(input);
} else if (isString(input)) {
} else if (isString2(input)) {
input = spreadUrlObject(parseUrl2(input));
} else {
callback = options;
@@ -100362,7 +100362,7 @@ var require_follow_redirects = __commonJS({
maxBodyLength: exports3.maxBodyLength
}, input, options);
options.nativeProtocols = nativeProtocols;
if (!isString(options.host) && !isString(options.hostname)) {
if (!isString2(options.host) && !isString2(options.hostname)) {
options.hostname = "::1";
}
assert.equal(options.protocol, protocol, "protocol mismatch");
@@ -100389,7 +100389,7 @@ var require_follow_redirects = __commonJS({
parsed = new URL2(input);
} else {
parsed = validateUrl(url.parse(input));
if (!isString(parsed.protocol)) {
if (!isString2(parsed.protocol)) {
throw new InvalidUrlError({ input });
}
}
@@ -100461,11 +100461,11 @@ var require_follow_redirects = __commonJS({
request2.destroy(error3);
}
function isSubdomain(subdomain, domain) {
assert(isString(subdomain) && isString(domain));
assert(isString2(subdomain) && isString2(domain));
var dot = subdomain.length - domain.length - 1;
return dot > 0 && subdomain[dot] === "." && subdomain.endsWith(domain);
}
function isString(value) {
function isString2(value) {
return typeof value === "string" || value instanceof String;
}
function isFunction(value) {
@@ -104408,9 +104408,21 @@ var RepositoryPropertyName = /* @__PURE__ */ ((RepositoryPropertyName2) => {
RepositoryPropertyName2["EXTRA_QUERIES"] = "github-codeql-extra-queries";
return RepositoryPropertyName2;
})(RepositoryPropertyName || {});
function isString(value) {
return typeof value === "string";
}
var stringProperty = {
validate: isString,
parse: parseStringRepositoryProperty
};
var booleanProperty = {
// The value from the API should come as a string, which we then parse into a boolean.
validate: isString,
parse: parseBooleanRepositoryProperty
};
var repositoryPropertyParsers = {
["github-codeql-disable-overlay" /* DISABLE_OVERLAY */]: parseBooleanRepositoryProperty,
["github-codeql-extra-queries" /* EXTRA_QUERIES */]: parseStringRepositoryProperty
["github-codeql-disable-overlay" /* DISABLE_OVERLAY */]: booleanProperty,
["github-codeql-extra-queries" /* EXTRA_QUERIES */]: stringProperty
};
async function loadPropertiesFromApi(gitHubVersion, logger, repositoryNwo) {
if (gitHubVersion.type === "GitHub Enterprise Server" /* GHES */) {
@@ -104435,11 +104447,6 @@ async function loadPropertiesFromApi(gitHubVersion, logger, repositoryNwo) {
);
}
if (isKnownPropertyName(property.property_name)) {
if (typeof property.value !== "string") {
throw new Error(
`Expected repository property '${property.property_name}' to have a string value, but got: ${JSON.stringify(property)}`
);
}
setProperty2(properties, property.property_name, property.value, logger);
}
}
@@ -104463,7 +104470,14 @@ async function loadPropertiesFromApi(gitHubVersion, logger, repositoryNwo) {
}
}
function setProperty2(properties, name, value, logger) {
properties[name] = repositoryPropertyParsers[name](name, value, logger);
const propertyOptions = repositoryPropertyParsers[name];
if (propertyOptions.validate(value)) {
properties[name] = propertyOptions.parse(name, value, logger);
} else {
throw new Error(
`Unexpected value for repository property '${name}', got: ${JSON.stringify(value)}`
);
}
}
function parseBooleanRepositoryProperty(name, value, logger) {
if (value !== "true" && value !== "false") {