Skip to content

Commit 51de085

Browse files
committed
Refined the 'isQuoted' method
1 parent 1d7973e commit 51de085

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/string-util/string-util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ export class StringUtil implements IStringUtil {
115115
* @returns {boolean}
116116
*/
117117
public isQuoted (str: string): boolean {
118-
return this.startsWithQuote(str) && this.endsWithQuote(str);
118+
const trimmed = this.removeWhitespace(str, true);
119+
return this.startsWithQuote(trimmed) && this.endsWithQuote(trimmed);
119120
}
120121

121122
/**

test/string-util/string-util.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,16 @@ test("StringUtil () => Correctly determines if a string contains whitespace #6",
7070

7171
test("StringUtil () => Correctly determines if a string contains whitespace #7", t => {
7272
t.false(stringUtil.containsWhitespace("foo"));
73+
});
74+
75+
test("StringUtil () => Correctly determines if a string is quoted #1", t => {
76+
t.true(stringUtil.isQuoted(`"foo"`));
77+
});
78+
79+
test("StringUtil () => Correctly determines if a string is quoted #2", t => {
80+
t.true(stringUtil.isQuoted(`" foo "`));
81+
});
82+
83+
test("StringUtil () => Correctly determines if a string is quoted #3", t => {
84+
t.false(stringUtil.isQuoted(`foo`));
7385
});

0 commit comments

Comments
 (0)