rsnext/packages/next/build/generate-build-id.ts
Shahzeb K 25deefbba7 Avoid "ad" anywhere in the buildId (#6854)
* Added a check for ad_ in the buildId

* ad_ > ad

Co-Authored-By: lfades <luis@zeit.co>

* Update the `ad` comment

Co-Authored-By: lfades <luis@zeit.co>

* Avoid all buildId's that contain "ad"

Looking through the uBlock Origin filter list, it uses regex wildcards to avoid various things with "ad" anywhere in the string. It's a safe bet to just avoid "ad" all together (as opposed to just at the start).

* Use regex (case incensitive) to check for "ad" 

The following cases will set this regex to true:

```
/ad/i.test("somead")
/ad/i.test("someADlksdjf")
/ad/i.test("adlksdjf")
/ad/i.test("ADlksdjf")
```
2019-04-01 20:40:43 -04:00

17 lines
603 B
TypeScript

export async function generateBuildId (generate: () => string|null, fallback: () => string): Promise<string> {
let buildId = await generate()
// If there's no buildId defined we'll fall back
if (buildId === null) {
// We also create a new buildId if it starts with `ad` to avoid false
// positives with ad blockers
while (!buildId || /ad/i.test(buildId)) {
buildId = fallback()
}
}
if (typeof buildId !== 'string') {
throw new Error('generateBuildId did not return a string. https://err.sh/zeit/next.js/generatebuildid-not-a-string')
}
return buildId.trim()
}