Skip to content

Commit

Permalink
Fixed issue 786
Browse files Browse the repository at this point in the history
  • Loading branch information
Yan Gorelik committed Jun 7, 2018
1 parent b257cdb commit 8acaafa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
15 changes: 15 additions & 0 deletions sdk/go/core/tests/levels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,21 @@ func (suite *SanityLevelsTestSuite) TestOcPattern() {
suite.CRUD.Delete(&suite.Provider, &ocADel)
}

func (suite *SanityLevelsTestSuite) TestEmbeddedQuotes() {
runner := ysanity.Runner{}
l1 := ysanity.Runner_TwoKeyList{First: "ab'cd", Second: 11}
l2 := ysanity.Runner_TwoKeyList{First: "ab\"cd", Second: 22}
runner.TwoKeyList = []*ysanity.Runner_TwoKeyList {&l1, &l2}

suite.CRUD.Create(&suite.Provider, &runner)

runnerFilter := ysanity.Runner{}
runnerRead := suite.CRUD.Read(&suite.Provider, &runnerFilter)
suite.Equal(types.EntityEqual(&runner, runnerRead), true)

suite.CRUD.Delete(&suite.Provider, &runner)
}

func TestSanityLevelsTestSuite(t *testing.T) {
if testing.Verbose() {
ydk.EnableLogging(ydk.Debug)
Expand Down
11 changes: 11 additions & 0 deletions sdk/go/core/ydk/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,3 +790,14 @@ func EntityEqual(x, y Entity) bool {
}
return deepValueEqual(x, y)
}

func AddKeyToken(attr interface{}, attrName string) string {
attrStr := fmt.Sprintf("%v", attr)
var token string
if strings.Index(attrStr, "'") >= 0 {
token = fmt.Sprintf("[%s=\"%s\"]", attrName, attrStr)
} else {
token = fmt.Sprintf("[%s='%s']", attrName, attrStr)
}
return token
}
11 changes: 5 additions & 6 deletions ydkgen/printer/go/class_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,14 @@ def _print_segment_path(fp, data_alias):
key_props = fp.clazz.get_key_props()
predicate = '"'
for key_prop in key_props:
prefix = ''
key_name = ''
if key_prop.stmt.i_module.arg != fp.clazz.stmt.i_module.arg:
prefix = '%s:' % (key_prop.stmt.i_module.arg)
key_name += key_prop.stmt.i_module.arg
key_name += ':'
key_name += key_prop.stmt.arg

predicate = '''{0}"[%s%s='"{0}fmt.Sprintf("%%v", %s.%s){0}"']"'''
path.append(" + types.AddKeyToken(%s.%s, \"%s\")" % (fp.class_alias, key_prop.go_name(), key_name))

predicate = predicate.format(' + ') % (
prefix, key_prop.stmt.arg, fp.class_alias, key_prop.go_name())
path.append(predicate)
fp.ctx.writeln('%s.SegmentPath = %s' % (data_alias, ''.join(path)))

@staticmethod
Expand Down

0 comments on commit 8acaafa

Please sign in to comment.