Skip to content

Commit

Permalink
Merge 1fa0c4a into ee4d163
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienverge committed Jan 5, 2021
2 parents ee4d163 + 1fa0c4a commit b710d35
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/rules/test_quoted_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,21 @@ def test_only_when_needed_extras(self):
'- foo bar\n'
'- "foo bar"\n',
conf, problem1=(3, 3), problem2=(7, 3), problem3=(11, 3))

def test_octal_values(self):
conf = 'quoted-strings: {required: true}\n'

self.check('---\n'
'- 100\n'
'- 0100\n'
'- 0o100\n'
'- 777\n'
'- 0777\n'
'- 0o777\n'
'- 800\n'
'- 0800\n'
'- 0o800\n'
'- "0800"\n'
'- "0o800"\n',
conf,
problem1=(9, 3), problem2=(10, 3))
11 changes: 11 additions & 0 deletions yamllint/rules/quoted_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ def VALIDATE(conf):

DEFAULT_SCALAR_TAG = u'tag:yaml.org,2002:str'

# https://stackoverflow.com/a/36514274
yaml.resolver.Resolver.add_implicit_resolver(
'tag:yaml.org,2002:int',
re.compile(r'''^(?:[-+]?0b[0-1_]+
|[-+]?0o?[0-7_]+
|[-+]?0[0-7_]+
|[-+]?(?:0|[1-9][0-9_]*)
|[-+]?0x[0-9a-fA-F_]+
|[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+)$''', re.X),
list('-+0123456789'))


def _quote_match(quote_type, token_style):
return ((quote_type == 'any') or
Expand Down

0 comments on commit b710d35

Please sign in to comment.