From cc2d7f407251d7aee77ea8742edb2ab20639696e Mon Sep 17 00:00:00 2001 From: HamletDRC Date: Thu, 2 Feb 2017 08:18:07 +0100 Subject: [PATCH] #338 Bug: no-http-string's description says start, but it checks for any closes #338 --- src/noHttpStringRule.ts | 2 +- src/tests/NoHttpStringRuleTests.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/noHttpStringRule.ts b/src/noHttpStringRule.ts index 18c3ef6ca..d00c25887 100644 --- a/src/noHttpStringRule.ts +++ b/src/noHttpStringRule.ts @@ -40,7 +40,7 @@ class NoHttpStringWalker extends ErrorTolerantWalker { protected visitStringLiteral(node: ts.StringLiteral): void { const stringText : string = (node).text; // tslint:disable no-http-string - if (stringText.indexOf('http:') !== -1) { + if (stringText.indexOf('http:') === 0) { if (!this.isSuppressed(stringText)) { const failureString = Rule.FAILURE_STRING + '\'' + stringText + '\''; const failure = this.createFailure(node.getStart(), node.getWidth(), failureString); diff --git a/src/tests/NoHttpStringRuleTests.ts b/src/tests/NoHttpStringRuleTests.ts index 53e16f4ed..7c81c0734 100644 --- a/src/tests/NoHttpStringRuleTests.ts +++ b/src/tests/NoHttpStringRuleTests.ts @@ -36,6 +36,11 @@ describe('noHttpStringRule', (): void => { TestHelper.assertViolations(ruleName, inputScript, []); }); + it('should allow http in middle of string', (): void => { + const inputScript: string = 'var x = \'The prototcol may be http:// or https://\''; + TestHelper.assertViolations(ruleName, inputScript, []); + }); + it('should allow https strings in default values', (): void => { const inputScript: string = 'function f(x : string = \'https://www.microsoft.com\') {}'; TestHelper.assertViolations(ruleName, inputScript, []);