Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/Utils/CommonUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ exports.getDefaultTestRunName = getDefaultTestRunName;
exports.getDefaultRunDescription = getDefaultRunDescription;
exports.validateTestRunParamsFromPipeline = validateTestRunParamsFromPipeline;
exports.getAllFileErrors = getAllFileErrors;
exports.sanitisePipelineNameHeader = sanitisePipelineNameHeader;
const { v4: uuidv4 } = require('uuid');
const util_1 = require("util");
const GeneralConstants_1 = require("../Constants/GeneralConstants");
Expand Down Expand Up @@ -484,3 +485,26 @@ function getAllFileErrors(testObj) {
}
return fileErrors;
}
/**
* This function returns the string with only ascii charaters, removing the non-ascii characters.
* @param pipelineName - original pipeline name
* @returns sanitised pipeline name with only ascii characters
*/
function sanitisePipelineNameHeader(pipelineName) {
if (!pipelineName) {
return pipelineName;
}
let result = "";
for (const ch of pipelineName) {
const code = ch.codePointAt(0);
const allowed = (code >= 32 && code <= 126); // ASCII characters range, the only allowed characters in headers.
if (allowed) {
result += ch;
}
}
result = result.trim();
if (result.length == 0) {
result = "-"; // this is what GH does when i try to give all non-ascii characters in the repo name.
}
return result;
}
2 changes: 1 addition & 1 deletion lib/Utils/FetchUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function httpClientRetries(urlSuffix_1, header_1, method_1) {
const runId = process.env.GITHUB_RUN_ID;
const pipelineName = process.env.GITHUB_WORKFLOW || "Unknown Pipeline";
const pipelineUri = `${githubBaseUrl}/${repository}/actions/runs/${runId}`;
header['x-ms-pipeline-name'] = pipelineName; // setting these for patch calls.
header['x-ms-pipeline-name'] = (0, CommonUtils_1.sanitisePipelineNameHeader)(pipelineName); // setting these for patch calls.
header['x-ms-pipeline-uri'] = pipelineUri;
httpResponse = yield httpClient.request(methodEnumToString[method], urlSuffix, data, header);
}
Expand Down
24 changes: 24 additions & 0 deletions src/Utils/CommonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,27 @@ export function getAllFileErrors(testObj:TestModel | null): { [key: string]: str

return fileErrors;
}

/**
* This function returns the string with only ascii charaters, removing the non-ascii characters.
* @param pipelineName - original pipeline name
* @returns sanitised pipeline name with only ascii characters
*/
export function sanitisePipelineNameHeader(pipelineName: string | null): string | null {
if(!pipelineName) {
return pipelineName;
}
let result = "";
for (const ch of pipelineName) {
const code = ch.codePointAt(0)!;
const allowed = (code >= 32 && code <= 126); // ASCII characters range, the only allowed characters in headers.
if(allowed) {
result += ch;
}
}
result = result.trim();
if(result.length == 0) {
result = "-"; // this is what GH does when i try to give all non-ascii characters in the repo name.
}
return result;
}
4 changes: 2 additions & 2 deletions src/Utils/FetchUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IHeaders, IHttpClientResponse } from 'typed-rest-client/Interfaces';
import { errorCorrection, getResultObj, getUniqueId, sleep } from './CommonUtils';
import { errorCorrection, getResultObj, getUniqueId, sanitisePipelineNameHeader, sleep } from './CommonUtils';
import { FetchCallType, correlationHeader } from './../models/UtilModels';
import * as httpc from 'typed-rest-client/HttpClient';
import { uploadFileData } from './FileUtils';
Expand Down Expand Up @@ -37,7 +37,7 @@ export async function httpClientRetries(urlSuffix : string, header : IHeaders, m
const pipelineName = process.env.GITHUB_WORKFLOW || "Unknown Pipeline";
const pipelineUri = `${githubBaseUrl}/${repository}/actions/runs/${runId}`;

header['x-ms-pipeline-name'] = pipelineName; // setting these for patch calls.
header['x-ms-pipeline-name'] = sanitisePipelineNameHeader(pipelineName); // setting these for patch calls.
header['x-ms-pipeline-uri'] = pipelineUri;
httpResponse = await httpClient.request(methodEnumToString[method], urlSuffix, data, header);
}
Expand Down
48 changes: 48 additions & 0 deletions test/CommonUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { sanitisePipelineNameHeader } from "../src/Utils/CommonUtils";
describe("CommonUtils tests", () => {
it.each([
{
input: "Pipeline@2025#Release$!",
expected: "Pipeline@2025#Release$!"
},
{
input: "Build_Definition-01 (Test) ",
expected: "Build_Definition-01 (Test)"
},
{
input: "Normal Name",
expected: "Normal Name"
},
{
input: "Special*&^%$#@!Characters",
expected: "Special*&^%$#@!Characters"
},
{
input: "",
expected: ""
},
{
input: " ",
expected: "-"
},
{
input: "Name_with_underscores_and-dashes",
expected: "Name_with_underscores_and-dashes"
},
{
input: null,
expected: null
},
{
input: "🚀 Deploy",
expected: "Deploy"
},
{
input: "流水线-test-𰻞",
expected: "-test-"
}
])("sanitisePipelineNameHeader removes special characters", ({ input, expected }) => {
const result = sanitisePipelineNameHeader(input);
expect(result).toBe(expected);
});
});
Loading