diff --git a/content/actions/hosting-your-own-runners/managing-access-to-self-hosted-runners-using-groups.md b/content/actions/hosting-your-own-runners/managing-access-to-self-hosted-runners-using-groups.md index d6410327232f..cff123387c26 100644 --- a/content/actions/hosting-your-own-runners/managing-access-to-self-hosted-runners-using-groups.md +++ b/content/actions/hosting-your-own-runners/managing-access-to-self-hosted-runners-using-groups.md @@ -48,7 +48,9 @@ When creating a group, you must choose a policy that defines which repositories {% warning %} **Warning** + {% indented_data_reference site.data.reusables.github-actions.self-hosted-runner-security spaces=3 %} + For more information, see "[About self-hosted runners](/actions/hosting-your-own-runners/about-self-hosted-runners#self-hosted-runner-security-with-public-repositories)." {% endwarning %} @@ -78,7 +80,9 @@ When creating a group, you must choose a policy that defines which organizations {% warning %} **Warning** + {% indented_data_reference site.data.reusables.github-actions.self-hosted-runner-security spaces=3 %} + For more information, see "[About self-hosted runners](/actions/hosting-your-own-runners/about-self-hosted-runners#self-hosted-runner-security-with-public-repositories)." {% endwarning %} diff --git a/data/reusables/github-actions/self-hosted-runner-configure-runner-group-access.md b/data/reusables/github-actions/self-hosted-runner-configure-runner-group-access.md index 3b16ae0499dc..3b2ba51feb03 100644 --- a/data/reusables/github-actions/self-hosted-runner-configure-runner-group-access.md +++ b/data/reusables/github-actions/self-hosted-runner-configure-runner-group-access.md @@ -5,7 +5,9 @@ {% warning %} **Warning** + {% indented_data_reference site.data.reusables.github-actions.self-hosted-runner-security spaces=3 %} + For more information, see "[About self-hosted runners](/actions/hosting-your-own-runners/about-self-hosted-runners#self-hosted-runner-security-with-public-repositories)." {% endwarning %} diff --git a/jest.config.js b/jest.config.js index 5c7bae7ab73c..6b22ede91ad2 100644 --- a/jest.config.js +++ b/jest.config.js @@ -26,7 +26,7 @@ module.exports = { testPathIgnorePatterns: [ 'node_modules/', 'vendor/', - 'tests/helpers.js', + 'tests/helpers/', ...isBrowser ? [] : ['tests/browser/browser.js'] ], testMatch: [ diff --git a/lib/liquid-tags/indented-data-reference.js b/lib/liquid-tags/indented-data-reference.js index 5355234d7517..da254f24615b 100644 --- a/lib/liquid-tags/indented-data-reference.js +++ b/lib/liquid-tags/indented-data-reference.js @@ -1,6 +1,4 @@ const Liquid = require('liquid') -const liquid = new Liquid.Engine() -const LiquidTag = require('./liquid-tag') const assert = require('assert') // This class supports a tag that expects two parameters, a data reference and `spaces=NUMBER`: @@ -12,17 +10,14 @@ const assert = require('assert') // reference is used inside a block element (like a list or nested list) without // affecting the formatting when the reference is used elsewhere via {{ site.data.foo.bar }}. -module.exports = class IndentedDataReference extends LiquidTag { - constructor (template, tagName, dataReferenceAndNumberOfSpaces) { - super(template, tagName, dataReferenceAndNumberOfSpaces.trim()) - } - - async parseTemplate (context) { - const template = await this.getTemplate() - +module.exports = class IndentedDataReference extends Liquid.Tag { + async render (context) { // obfuscate first legit space, remove all other spaces, then restore legit space // this way we can support spaces=NUMBER as well as spaces = NUMBER - const input = this.param.replace(/\s/, 'REALSPACE').replace(/\s/g, '').replace('REALSPACE', ' ') + const input = this.markup.trim() + .replace(/\s/, 'REALSPACE') + .replace(/\s/g, '') + .replace('REALSPACE', ' ') const [dataReference, spaces] = input.split(' ') @@ -31,11 +26,16 @@ module.exports = class IndentedDataReference extends LiquidTag { assert(parseInt(numSpaces) || numSpaces === '0', '"spaces=NUMBER" must include a number') - const renderedReference = await require('../render-content')(`{{ ${dataReference} }}`, context.environments[0]) + // Get the referenced value from the context + const value = await context.get(dataReference) + + // If nothing is found in the context, exit with nothing; this may + // feel weird and that we should throw an error, but this is "The Liquid Way TM" + if (!value) return // add spaces to each line - const renderedReferenceWithIndent = renderedReference.replace(/^/mg, ' '.repeat(numSpaces)) + const renderedReferenceWithIndent = value.replace(/^/mg, ' '.repeat(numSpaces)) - return liquid.parseAndRender(template, { renderedReferenceWithIndent }) + return this.template.engine.parseAndRender(renderedReferenceWithIndent, context) } } diff --git a/script/check-deps.js b/script/check-deps.js index 36ac0052df67..ca917be5a1ee 100644 --- a/script/check-deps.js +++ b/script/check-deps.js @@ -17,6 +17,7 @@ const path = require('path') const main = async () => { const data = await dependencyCheck({ entries: [ + path.posix.join(__dirname, '..', '*.js'), path.posix.join(__dirname, '..', '*', '*.js'), path.posix.join('!', __dirname, '..', 'javascripts', '*.js'), path.posix.join(__dirname, '..', 'script', 'graphql', '*.js') diff --git a/tests/content/featured-links.js b/tests/content/featured-links.js index 21f010871a55..c5b476153bcb 100644 --- a/tests/content/featured-links.js +++ b/tests/content/featured-links.js @@ -1,4 +1,4 @@ -const { getDOM, getJSON } = require('../helpers') +const { getDOM, getJSON } = require('../helpers/supertest') const enterpriseServerReleases = require('../../lib/enterprise-server-releases') const japaneseCharacters = require('japanese-characters') const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version') diff --git a/tests/content/site-tree.js b/tests/content/site-tree.js index 0625205f02d4..fd64445ec325 100644 --- a/tests/content/site-tree.js +++ b/tests/content/site-tree.js @@ -1,7 +1,7 @@ const revalidator = require('revalidator') const schema = require('../../lib/site-tree-schema') const latestEnterpriseRelease = require('../../lib/enterprise-server-releases').latest -const { getJSON } = require('../helpers') +const { getJSON } = require('../helpers/supertest') const flat = require('flat') const japaneseCharacters = require('japanese-characters') const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version') diff --git a/tests/content/webhooks.js b/tests/content/webhooks.js index 1baf790fd68a..e14b8c791c56 100644 --- a/tests/content/webhooks.js +++ b/tests/content/webhooks.js @@ -1,5 +1,5 @@ const { difference } = require('lodash') -const { getJSON } = require('../helpers') +const { getJSON } = require('../helpers/supertest') const { latest } = require('../../lib/enterprise-server-releases') const allVersions = Object.values(require('../../lib/all-versions')) const payloadVersions = allVersions.map(v => v.miscVersionName) diff --git a/tests/helpers.js b/tests/helpers/supertest.js similarity index 97% rename from tests/helpers.js rename to tests/helpers/supertest.js index 2090dd2696fc..7ffcbb73ebbe 100644 --- a/tests/helpers.js +++ b/tests/helpers/supertest.js @@ -3,7 +3,7 @@ const cheerio = require('cheerio') const supertest = require('supertest') -const app = require('../server') +const app = require('../../server') const helpers = {} diff --git a/tests/meta/orphan-tests.js b/tests/meta/orphan-tests.js index ca5f77b2674e..770b10389cfd 100644 --- a/tests/meta/orphan-tests.js +++ b/tests/meta/orphan-tests.js @@ -4,7 +4,7 @@ const path = require('path') describe('check for orphan tests', () => { test('all tests are in sub-directories', () => { // A known list of exceptions that can live outside of directories - const EXCEPTIONS = ['README.md', 'helpers.js'] + const EXCEPTIONS = ['README.md'] const pathToTests = path.join(process.cwd(), 'tests') // Get a list of files/directories in `/tests` diff --git a/tests/rendering/breadcrumbs.js b/tests/rendering/breadcrumbs.js index 422b0428397e..3395ba626662 100644 --- a/tests/rendering/breadcrumbs.js +++ b/tests/rendering/breadcrumbs.js @@ -1,4 +1,4 @@ -const { getDOM, getJSON } = require('../helpers') +const { getDOM, getJSON } = require('../helpers/supertest') const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version') describe('breadcrumbs', () => { diff --git a/tests/rendering/curated-homepage-links.js b/tests/rendering/curated-homepage-links.js index 6dfa89385f28..86a24804c355 100644 --- a/tests/rendering/curated-homepage-links.js +++ b/tests/rendering/curated-homepage-links.js @@ -1,4 +1,4 @@ -const { getDOM } = require('../helpers') +const { getDOM } = require('../helpers/supertest') describe('curated homepage links', () => { jest.setTimeout(5 * 60 * 1000) diff --git a/tests/rendering/footer.js b/tests/rendering/footer.js index d2c0f26d3600..59a0ed472946 100644 --- a/tests/rendering/footer.js +++ b/tests/rendering/footer.js @@ -1,4 +1,4 @@ -const { getDOM } = require('../helpers') +const { getDOM } = require('../helpers/supertest') const enterpriseServerReleases = require('../../lib/enterprise-server-releases') const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version') diff --git a/tests/rendering/head.js b/tests/rendering/head.js index 9d6f3e5def2d..9774017b2ff2 100644 --- a/tests/rendering/head.js +++ b/tests/rendering/head.js @@ -1,4 +1,4 @@ -const { getDOM } = require('../helpers') +const { getDOM } = require('../helpers/supertest') const languages = require('../../lib/languages') describe('
', () => { diff --git a/tests/rendering/header.js b/tests/rendering/header.js index 4965bc037de8..3847ed2bf04d 100644 --- a/tests/rendering/header.js +++ b/tests/rendering/header.js @@ -1,4 +1,4 @@ -const { getDOM } = require('../helpers') +const { getDOM } = require('../helpers/supertest') const { oldestSupported, latest } = require('../../lib/enterprise-server-releases') const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version') diff --git a/tests/rendering/page-titles.js b/tests/rendering/page-titles.js index 711c983e1423..34be39c65b58 100644 --- a/tests/rendering/page-titles.js +++ b/tests/rendering/page-titles.js @@ -1,5 +1,5 @@ const enterpriseServerReleases = require('../../lib/enterprise-server-releases') -const { getDOM } = require('../helpers') +const { getDOM } = require('../helpers/supertest') describe('page titles', () => { jest.setTimeout(300 * 1000) diff --git a/tests/rendering/rest.js b/tests/rendering/rest.js index ac43413933fa..d26e1b74ad40 100644 --- a/tests/rendering/rest.js +++ b/tests/rendering/rest.js @@ -1,7 +1,7 @@ const fs = require('fs') const path = require('path') const { difference, isPlainObject } = require('lodash') -const { getJSON } = require('../helpers') +const { getJSON } = require('../helpers/supertest') const enterpriseServerReleases = require('../../lib/enterprise-server-releases') // list of REST markdown files that do not correspond to REST API resources // TODO could we get this list dynamically, say via page frontmatter? diff --git a/tests/rendering/robots-txt.js b/tests/rendering/robots-txt.js index eb41c64e190b..14154acbf159 100644 --- a/tests/rendering/robots-txt.js +++ b/tests/rendering/robots-txt.js @@ -1,7 +1,7 @@ const languages = require('../../lib/languages') const robotsParser = require('robots-parser') const robotsMiddleware = require('../../middleware/robots') -const { get } = require('../helpers') +const { get } = require('../helpers/supertest') const MockExpressResponse = require('mock-express-response') const products = require('../../lib/all-products') const enterpriseServerReleases = require('../../lib/enterprise-server-releases') diff --git a/tests/rendering/server.js b/tests/rendering/server.js index 82651eba04d2..be5eac5385e1 100644 --- a/tests/rendering/server.js +++ b/tests/rendering/server.js @@ -1,6 +1,6 @@ const lodash = require('lodash') const enterpriseServerReleases = require('../../lib/enterprise-server-releases') -const { get, getDOM, head } = require('../helpers') +const { get, getDOM, head } = require('../helpers/supertest') const path = require('path') const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version') diff --git a/tests/rendering/sidebar.js b/tests/rendering/sidebar.js index a64d4f31eadf..51afa72bb02e 100644 --- a/tests/rendering/sidebar.js +++ b/tests/rendering/sidebar.js @@ -1,4 +1,4 @@ -const { getDOM } = require('../helpers') +const { getDOM } = require('../helpers/supertest') const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version') describe('sidebar', () => { diff --git a/tests/routing/deprecated-enterprise-versions.js b/tests/routing/deprecated-enterprise-versions.js index 76f4863cd7af..9b5ea537d781 100644 --- a/tests/routing/deprecated-enterprise-versions.js +++ b/tests/routing/deprecated-enterprise-versions.js @@ -1,6 +1,6 @@ const app = require('../../server') const enterpriseServerReleases = require('../../lib/enterprise-server-releases') -const { get, getDOM } = require('../helpers') +const { get, getDOM } = require('../helpers/supertest') const supertest = require('supertest') describe('enterprise deprecation', () => { diff --git a/tests/routing/developer-site-redirects.js b/tests/routing/developer-site-redirects.js index 112feed352b5..7378066dc9d7 100644 --- a/tests/routing/developer-site-redirects.js +++ b/tests/routing/developer-site-redirects.js @@ -1,6 +1,6 @@ const { eachOfLimit } = require('async') const enterpriseServerReleases = require('../../lib/enterprise-server-releases') -const { get } = require('../helpers') +const { get } = require('../helpers/supertest') const { getEnterpriseVersionNumber } = require('../../lib/patterns') const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version') const restRedirectFixtures = require('../fixtures/rest-redirects') diff --git a/tests/routing/enterprise-release-notes.js b/tests/routing/enterprise-release-notes.js index c88701f8be33..fb05e3186962 100644 --- a/tests/routing/enterprise-release-notes.js +++ b/tests/routing/enterprise-release-notes.js @@ -1,4 +1,4 @@ -const { get } = require('../helpers') +const { get } = require('../helpers/supertest') describe('enterprise release notes', () => { jest.setTimeout(60 * 1000) diff --git a/tests/routing/language-code-redirects.js b/tests/routing/language-code-redirects.js index a7b5772c5d6b..0dba89bebe0b 100644 --- a/tests/routing/language-code-redirects.js +++ b/tests/routing/language-code-redirects.js @@ -1,4 +1,4 @@ -const { get } = require('../helpers') +const { get } = require('../helpers/supertest') describe('language code redirects', () => { jest.setTimeout(5 * 60 * 1000) diff --git a/tests/routing/redirects.js b/tests/routing/redirects.js index bb547c9e203c..740cd67d55d0 100644 --- a/tests/routing/redirects.js +++ b/tests/routing/redirects.js @@ -5,7 +5,7 @@ const app = require('../../server') const enterpriseServerReleases = require('../../lib/enterprise-server-releases') const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version') const Page = require('../../lib/page') -const { get } = require('../helpers') +const { get } = require('../helpers/supertest') describe('redirects', () => { jest.setTimeout(5 * 60 * 1000) diff --git a/tests/routing/top-developer-site-path-redirects.js b/tests/routing/top-developer-site-path-redirects.js index 2dbf24b09cd4..46554df23033 100644 --- a/tests/routing/top-developer-site-path-redirects.js +++ b/tests/routing/top-developer-site-path-redirects.js @@ -1,4 +1,4 @@ -const { head } = require('../helpers') +const { head } = require('../helpers/supertest') describe('developer.github.com redirects', () => { jest.setTimeout(30 * 60 * 1000) diff --git a/tests/unit/liquid-helpers.js b/tests/unit/liquid-helpers.js index c72a1fa58593..5d16ea038447 100644 --- a/tests/unit/liquid-helpers.js +++ b/tests/unit/liquid-helpers.js @@ -85,36 +85,32 @@ describe('liquid helper tags', () => { test('without any number of spaces specified', async () => { const template = '{% indented_data_reference site.data.reusables.example %}' - const expected = `a rose by any other name - would smell as sweet
-` + const expected = ` a rose by any other name + would smell as sweet` const output = await liquid.parseAndRender(template, context) expect(output).toBe(expected) }) test('with 0 spaces specified', async () => { const template = '{% indented_data_reference site.data.reusables.example spaces=0 %}' - const expected = `a rose by any other name -would smell as sweet
-` + const expected = `a rose by any other name +would smell as sweet` const output = await liquid.parseAndRender(template, context) expect(output).toBe(expected) }) test('with 0 spaces specified and whitespace around equals sign', async () => { const template = '{% indented_data_reference site.data.reusables.example spaces = 0 %}' - const expected = `a rose by any other name -would smell as sweet
-` + const expected = `a rose by any other name +would smell as sweet` const output = await liquid.parseAndRender(template, context) expect(output).toBe(expected) }) test('with 5 spaces specified', async () => { const template = '{% indented_data_reference site.data.reusables.example spaces=5 %}' - const expected = `a rose by any other name - would smell as sweet
-` + const expected = ` a rose by any other name + would smell as sweet` const output = await liquid.parseAndRender(template, context) expect(output).toBe(expected) }) diff --git a/tests/unit/products.js b/tests/unit/products.js index c57744b02079..db8b2e0828e3 100644 --- a/tests/unit/products.js +++ b/tests/unit/products.js @@ -1,7 +1,7 @@ const revalidator = require('revalidator') const products = require('../../lib/all-products') const schema = require('../../lib/products-schema') -const { getDOM, getJSON } = require('../helpers') +const { getDOM, getJSON } = require('../helpers/supertest') const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version') describe('products module', () => { diff --git a/tests/unit/versions.js b/tests/unit/versions.js index 93e6728ab685..1f3c8d2af763 100644 --- a/tests/unit/versions.js +++ b/tests/unit/versions.js @@ -2,7 +2,7 @@ const revalidator = require('revalidator') const allVersions = require('../../lib/all-versions') const { latest } = require('../../lib/enterprise-server-releases') const schema = require('../../lib/versions-schema') -const { getJSON } = require('../helpers') +const { getJSON } = require('../helpers/supertest') const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version') describe('versions module', () => {