enonic / lib-guillotine

Apache License 2.0
3 stars 0 forks source link

Confirm handling of _ and - in property names #73

Closed anatol-sialitski closed 3 years ago

anatol-sialitski commented 3 years ago

GraphQL does not support - characters in field names, but XP does. To mitigate this we currently replace - with _. However, if a field my-field and my_field exists at the same level, we would get a conflict.

Confirm that this is the current behaviour, and if there are any alternative ways of handling - names safely?

Guilltine 4: field_name -> field_name (was broken for item/optionset and fixed recently) field-name -> field_name fieldname -> fieldname fieldName -> fieldName

Also, what other characters will be problematic for Guillotine? I.e. cyrillics, øæå etc? What is allowed and not in node layer? What is documented? Should we restrict something in content API? Should there be options to specify guillotine

anatol-sialitski commented 3 years ago

ItemSet and OptionSet object types:

namePrefix + '_' + namingLib.generateCamelCase(itemSet.label, true);

field_name -> namePrefix_FieldName
field-name -> namePrefix_FieldName
fieldName -> namePrefix_FieldName
fieldname -> namePrefix_Fieldname

Fields of ItemSet and OptionSet

namingLib.generateCamelCase(item.name)

field_name -> fieldName
field-name -> fieldName
fieldName -> fieldName
fieldname -> fieldname

For each item of the content type form

namingLib.sanitizeText(formItem.name)

field_name -> field_name
field-name -> field_name
fieldName -> fieldName
fieldname -> fieldname

If on the same level there are the following fields:

<input name="field_name" type="TextLine">
  <label>Field_Name</label>
  <occurrences maximum="1" minimum="0"/>
</input>
<input name="field-name" type="HtmlArea">
  <label>Field-Name</label>
  <custom-text>text</custom-text>
  <occurrences maximum="1" minimum="0"/>
</input>

then in a result will be present only the last field, because both have the same name field_name after processing.

Q: what other characters will be problematic for Guillotine? I.e. cyrillics, øæå etc? A: In the current implementation all characters which are not mapped to 0-9A-Za-z will be replaced by _ (underscore). According to GraphQL Spec GraphQL supports the following characters for name http://spec.graphql.org/July2015/#Name.

Q: What is documented? A: I nothing found about field name and object name convention in the Guillotine docs.

PropertyTree and PropertySet can have properties name which starts from or contains only digits. In this case Guillotine will be failed.

anatol-sialitski commented 3 years ago

@sigdestad and @alansemenov please have a look at the result of research

sigdestad commented 3 years ago

So, are you saying itemset and optionset behave differently from regular fields?

anatol-sialitski commented 3 years ago

Yes, right.

sigdestad commented 3 years ago

It is a bit unclear for me. Can you create an example including "sets" and fields and show how the naming mapping is handled for them together?

anatol-sialitski commented 3 years ago

For the content type with the following definition:

<content-type>
  <display-name>MyContentType</display-name>
  <super-type>base:structured</super-type>
  <is-abstract>false</is-abstract>
  <is-final>true</is-final>
  <allow-child-content>true</allow-child-content>
  <form>
    <input type="TextLine" name="form_field_name_1">
      <label>form_field_name_1</label>
      <occurrences minimum="0" maximum="0"/>
    </input>
    <input type="TextLine" name="form_field-name-2">
      <label>form_field-name-2</label>
      <occurrences minimum="1" maximum="1"/>
    </input>
    <input type="TextLine" name="form_fieldname">
      <label>form_fieldname</label>
      <occurrences maximum="1" minimum="0"/>
    </input>
    <input type="HtmTextLinelArea" name="form_fieldName">
      <label>form_fieldName</label>
      <custom-text>text</custom-text>
      <occurrences maximum="1" minimum="0"/>
    </input>
    <item-set name="item-set">
      <label>Item Set</label>
      <occurrences maximum="0" minimum="0"/>
      <items>
        <input type="TextLine" name="item-set_field_name_1">
          <label>item-set_field_name_1</label>
          <occurrences minimum="0" maximum="0"/>
        </input>
        <input type="TextLine" name="item-set_field-name-2">
          <label>item-set_field-name-2</label>
          <occurrences minimum="1" maximum="1"/>
        </input>
        <input type="TextLine" name="item-set_fieldname">
          <label>item-set_fieldname</label>
          <occurrences maximum="1" minimum="0"/>
        </input>
        <input type="TextLine" name="item-set_fieldName">
          <label>item-set_fieldName</label>
          <occurrences maximum="1" minimum="0"/>
        </input>
      </items>
    </item-set>
  </form>
</content-type>

will be generated the following fields:

image

sigdestad commented 3 years ago

Ahh.. we definetly need to make this consistent. I guess we have two options: a) Always do like inside sets (no underscores) b) Same as outside sets (- becomes ) and we keep c) a bit of both, keep _ and kapitalcase items with -

What do you think?

Personally, I think c) feels like a nice compromise

sigdestad commented 3 years ago

Did you check out how we handle page components? I.e. parts and fields inside their config?

anatol-sialitski commented 3 years ago

For page/part/layout components the following behavior:

namingLib.sanitizeText(formItem.name)

field_name -> field_name
field-name -> field_name
fieldName -> fieldName
fieldname -> fieldname

image

anatol-sialitski commented 3 years ago

field_name -> field_name field-name -> field_name fieldName -> fieldName fieldname -> fieldname 1fieldName -> _1fieldName назаниеПоля -> nazaniepolja

Transliteration -> sinitize

anatol-sialitski commented 3 years ago

More examples

field+name -> field_name
field name -> field_name
field_name -> field_name
field-name -> field_name
field_Name -> field_Name
field-Name -> field_Name
fieldName -> fieldName
fieldname -> fieldname
123fieldName -> _123fieldName
fieldName123 -> fieldName123
fieldName-123 -> fieldName_123
fieldName_123 -> fieldName_123
fieldName 123 -> fieldName_123
названиеПолЯ -> nazvaniePolJA
#12названиеПоля?&*^% -> _12nazvaniePolja