From: Stas Vilchik Date: Wed, 10 Oct 2018 14:20:50 +0000 (+0200) Subject: SONAR-11303 fix {instance} replacement in docs X-Git-Tag: 7.5~321 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1da2b46a8136637073020efa4f171b2ee8693191;p=sonarqube.git SONAR-11303 fix {instance} replacement in docs --- diff --git a/server/sonar-docs/src/templates/page.js b/server/sonar-docs/src/templates/page.js index ad61a0fb70c..c60e2a964ef 100644 --- a/server/sonar-docs/src/templates/page.js +++ b/server/sonar-docs/src/templates/page.js @@ -101,7 +101,7 @@ export const query = graphql` `; function replaceInstanceTag(content) { - return content.replace('{instance}', 'SonarQube'); + return content.replace(/{instance}/gi, 'SonarQube'); } function replaceDynamicLinks(content) { diff --git a/server/sonar-web/src/main/js/helpers/__tests__/markdown-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/markdown-test.ts index 2e1db47c92e..453b37bd4fc 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/markdown-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/markdown-test.ts @@ -17,7 +17,12 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import { getFrontMatter, separateFrontMatter } from '../markdown'; +import { getFrontMatter, separateFrontMatter, filterContent } from '../markdown'; + +jest.mock('../system', () => ({ + getInstance: () => 'SonarQube', + isSonarCloud: () => false +})); it('returns parsed frontmatter of one item', () => { expect( @@ -105,3 +110,9 @@ it('returns full content when frontmatter has bad formatting', () => { expect(separateFrontMatter(content)).toEqual({ content, frontmatter: {} }); }); + +it('replaces {instance}', () => { + expect( + filterContent('This is {instance} content. It replaces all {instance}{instance} messages') + ).toBe('This is SonarQube content. It replaces all SonarQubeSonarQube messages'); +}); diff --git a/server/sonar-web/src/main/js/helpers/markdown.js b/server/sonar-web/src/main/js/helpers/markdown.js index b41e590fcad..ac084deda78 100644 --- a/server/sonar-web/src/main/js/helpers/markdown.js +++ b/server/sonar-web/src/main/js/helpers/markdown.js @@ -73,7 +73,7 @@ function parseFrontMatter(lines) { */ function filterContent(content) { const { isSonarCloud, getInstance } = require('./system'); - const contentWithInstance = content.replace('{instance}', getInstance()); + const contentWithInstance = content.replace(/{instance}/gi, getInstance()); const contentWithoutStatic = cutConditionalContent(contentWithInstance, 'static'); return isSonarCloud() ? cutConditionalContent(contentWithoutStatic, 'sonarqube')