sapmentors / cap-community

SAP CAP Community
MIT License
97 stars 26 forks source link

xs-security.json contains "[32m" and "[39m" when using compile --to xsuaa #47

Closed gregorwolf closed 4 years ago

gregorwolf commented 4 years ago

When I upgrade my example project bookshop-nodejs to @sap/cds version 3.31.1:

cds -v
@sap/cds: 3.31.1
@sap/cds-compiler: 1.23.2
@sap/cds-foss: 1.1.0
@sap/cds-messaging: 1.7.0
@sap/cds-reflect: 2.10.1
@sap/cds-rest: 1.5.1
@sap/cds-services: 1.25.1
Node.js: v12.16.1
home: /Users/gwolf/Documents/Projects/cap/bookshop-nodejs/node_modules/@sap/cds

and then run the command:

cds compile srv/ --to xsuaa > xs-security.json

the generated xs-security.json looks like this:

{
  xsappname: 'bookshop-nodejs',
  'tenant-mode': 'dedicated',
  scopes: [ { name: '$XSAPPNAME.admin', description: 'admin' } ],
  attributes: [],
  'role-templates': [
    {
      name: 'admin',
      description: 'generated',
      'scope-references': [ '$XSAPPNAME.admin' ],
      'attribute-references': []
    }
  ]
}

with 3.21.3 it was generated like this:

{
  "xsappname": "bookshop-nodejs",
  "tenant-mode": "dedicated",
  "scopes": [
    {
      "name": "$XSAPPNAME.admin",
      "description": "admin"
    }
  ],
  "attributes": [],
  "role-templates": [
    {
      "name": "admin",
      "description": "generated",
      "scope-references": [
        "$XSAPPNAME.admin"
      ],
      "attribute-references": []
    }
  ]
}
wattnu commented 4 years ago

I'm observing the very same for the transformation cds --> csn via the cds command. For instance:

cds .\samples.cds > samples.csn

When opening with VS Code Editor (it's guessing this to be UTF-16 LE), this shows up like:

{
  namespace: 'my.domain',
  definitions: [Object: null prototype] {
    'my.domain.Products': {
      kind: 'entity',
      elements: [Object: null prototype] {
        ID: { key: true, type: 'cds.Integer' },
        name: { type: 'cds.String', length: 100, notNull: true },
        stock: { type: 'cds.Integer' },
...

When I'm looking just at the command line output of cds samples.cds (Powershell), then everything looks fine!

Opening samples.csn with Notepad++ shows the little ?s as ESC. So searching for common ESCAPE code (https://bluesock.org/~willkg/dev/ansi.html), I've found this to be color code Escape Sequences! Somehow, these are polluting the output ....

Obviously, the command line is interpreting the color codes, the Editors don't.

gregorwolf commented 4 years ago

Is fixed with @sap/cds version 3.31.2