mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Fixed #557
This commit is contained in:
@@ -312,6 +312,30 @@ export function test_parse_ShouldParseSubProperties() {
|
||||
TKUnit.assert(sw.visibility === "collapsed", "Expected result: collapsed; Actual result: " + sw.visibility + "; type: " + typeof (sw.visibility));
|
||||
};
|
||||
|
||||
export function test_parse_ShouldParseBindingsWithCommaInsideSingleQuote() {
|
||||
var expected = "Hi,test"
|
||||
var bindingString = "{{ 'Hi,' + myProp }}";
|
||||
var p = <page.Page>builder.parse('<Page><Label text="' + bindingString + '" /></Page>');
|
||||
var obj = new observable.Observable();
|
||||
obj.set("myProp", "test");
|
||||
p.bindingContext = obj;
|
||||
var lbl = <labelModule.Label>p.content;
|
||||
|
||||
TKUnit.assert(lbl.text === expected, "Expected " + expected + "; Actual result: " + lbl.text + "; type: " + typeof (lbl.text));
|
||||
};
|
||||
|
||||
export function test_parse_ShouldParseBindingsWithCommaInsideDoubleQuote() {
|
||||
var expected = "Hi,test"
|
||||
var bindingString = '{{ "Hi," + myProp }}';
|
||||
var p = <page.Page>builder.parse("<Page><Label text='" + bindingString + "' /></Page>");
|
||||
var obj = new observable.Observable();
|
||||
obj.set("myProp", "test");
|
||||
p.bindingContext = obj;
|
||||
var lbl = <labelModule.Label>p.content;
|
||||
|
||||
TKUnit.assert(lbl.text === expected, "Expected " + expected + "; Actual result: " + lbl.text + "; type: " + typeof (lbl.text));
|
||||
};
|
||||
|
||||
export function test_parse_CanBindBackgroundImage() {
|
||||
var p = <page.Page>builder.parse("<Page><StackLayout backgroundImage='{{ myProp }}' /></Page>");
|
||||
var expected = "~/logo.png"
|
||||
|
||||
@@ -96,19 +96,33 @@ function getParamsArray(value: string) {
|
||||
var i;
|
||||
var skipComma = 0;
|
||||
var indexReached = 0;
|
||||
var singleQuoteBlock, doubleQuoteBlock = false;
|
||||
|
||||
for (i = 0; i < value.length; i++) {
|
||||
if (value[i] === '"') {
|
||||
doubleQuoteBlock = !doubleQuoteBlock;
|
||||
}
|
||||
|
||||
if (value[i] === "'") {
|
||||
singleQuoteBlock = !singleQuoteBlock;
|
||||
}
|
||||
|
||||
if (value[i] === '(' || value[i] === '[') {
|
||||
skipComma++;
|
||||
}
|
||||
|
||||
if (value[i] === ')' || value[i] === ']') {
|
||||
skipComma--;
|
||||
}
|
||||
if (value[i] === ',' && skipComma === 0) {
|
||||
|
||||
if (value[i] === ',' && skipComma === 0 && !(singleQuoteBlock || doubleQuoteBlock)) {
|
||||
result.push(value.substr(indexReached, i - indexReached));
|
||||
indexReached = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
result.push(value.substr(indexReached));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user