isomorphic-git 1.44.3 → 1.44.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -464,6 +464,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
464
464
  <td align="center"><a href="https://github.com/macabeus"><img src="https://avatars.githubusercontent.com/u/9501115?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Bruno Macabeus</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=macabeus" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=macabeus" title="Tests">⚠️</a></td>
465
465
  <td align="center"><a href="https://github.com/snowyukitty"><img src="https://avatars.githubusercontent.com/u/270071858?v=4?s=60" width="60px;" alt=""/><br /><sub><b>snowyukitty</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=snowyukitty" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=snowyukitty" title="Tests">⚠️</a></td>
466
466
  <td align="center"><a href="https://github.com/ShahabAhmed01"><img src="https://avatars.githubusercontent.com/u/192491541?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Shahab Ahmed</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=ShahabAhmed01" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=ShahabAhmed01" title="Tests">⚠️</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=ShahabAhmed01" title="Documentation">📖</a></td>
467
+ <td align="center"><a href="https://github.com/wleeaf"><img src="https://avatars.githubusercontent.com/u/179125857?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Wleeaf</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=wleeaf" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=wleeaf" title="Tests">⚠️</a></td>
467
468
  </tr>
468
469
  </table>
469
470
 
package/index.cjs CHANGED
@@ -1823,9 +1823,11 @@ const schema = {
1823
1823
  // section is alphanumeric (ASCII) with - and .
1824
1824
  // section is case insensitive
1825
1825
  // subsection is optional
1826
- // subsection is specified after section and one or more spaces
1827
- // subsection is specified between double quotes
1828
- const SECTION_LINE_REGEX = /^\[([A-Za-z0-9-.]+)(?: "(.*)")?\]$/;
1826
+ // subsection is specified after section and one or more spaces or tabs
1827
+ // subsection is specified between double quotes, where \ escapes the next character
1828
+ // a comment can follow the section header
1829
+ const SECTION_LINE_REGEX =
1830
+ /^\[([A-Za-z0-9-.]+)(?:[ \t]+"((?:[^"\\]|\\.)*)")?\][ \t]*(?:[#;].*)?$/;
1829
1831
  const SECTION_REGEX = /^[A-Za-z0-9-.]+$/;
1830
1832
 
1831
1833
  // variable lines contain a name, and equal sign and then a value
@@ -1837,14 +1839,12 @@ const SECTION_REGEX = /^[A-Za-z0-9-.]+$/;
1837
1839
  const VARIABLE_LINE_REGEX = /^([A-Za-z][A-Za-z0-9-]*)(?:\s*=\s*(.*))?$/;
1838
1840
  const VARIABLE_NAME_REGEX = /^[A-Za-z][A-Za-z0-9-]*$/;
1839
1841
 
1840
- // Comments start with either # or ; and extend to the end of line
1841
- const VARIABLE_VALUE_COMMENT_REGEX = /^(.*?)( *[#;].*)$/;
1842
-
1843
1842
  const extractSectionLine = line => {
1844
1843
  const matches = SECTION_LINE_REGEX.exec(line);
1845
1844
  if (matches != null) {
1846
1845
  const [section, subsection] = matches.slice(1);
1847
- return [section, subsection]
1846
+ // Like canonical git, drop the backslash of an escaped character
1847
+ return [section, subsection && subsection.replace(/\\(.)/g, '$1')]
1848
1848
  }
1849
1849
  return null
1850
1850
  };
@@ -1853,43 +1853,61 @@ const extractVariableLine = line => {
1853
1853
  const matches = VARIABLE_LINE_REGEX.exec(line);
1854
1854
  if (matches != null) {
1855
1855
  const [name, rawValue = 'true'] = matches.slice(1);
1856
- const valueWithoutComments = removeComments(rawValue);
1857
- const valueWithoutQuotes = removeQuotes(valueWithoutComments);
1858
- return [name, valueWithoutQuotes]
1856
+ return [name, parseValue(rawValue)]
1859
1857
  }
1860
1858
  return null
1861
1859
  };
1862
1860
 
1863
- const removeComments = rawValue => {
1864
- const commentMatches = VARIABLE_VALUE_COMMENT_REGEX.exec(rawValue);
1865
- if (commentMatches == null) {
1866
- return rawValue
1867
- }
1868
- const [valueWithoutComment, comment] = commentMatches.slice(1);
1869
- // if odd number of quotes before and after comment => comment is escaped
1870
- if (
1871
- hasOddNumberOfQuotes(valueWithoutComment) &&
1872
- hasOddNumberOfQuotes(comment)
1873
- ) {
1874
- return `${valueWithoutComment}${comment}`
1861
+ const ESCAPED_CHARS = new Map([
1862
+ ['t', '\t'],
1863
+ ['b', '\b'],
1864
+ ['n', '\n'],
1865
+ ['\\', '\\'],
1866
+ ['"', '"'],
1867
+ ]);
1868
+
1869
+ // This follows parse_value in config.c of canonical git: double quotes are
1870
+ // removed, # and ; outside of quotes start a comment, whitespace outside of
1871
+ // quotes is kept between words but trimmed at the end, and \t, \b, \n, \\ and
1872
+ // \" are unescaped. Canonical git rejects any other escape sequence, here the
1873
+ // backslash is kept as is.
1874
+ const parseValue = rawValue => {
1875
+ let value = '';
1876
+ let pendingSpace = '';
1877
+ let inQuotes = false;
1878
+ for (let i = 0; i < rawValue.length; i++) {
1879
+ const c = rawValue[i];
1880
+ if (!inQuotes && /[ \t\r\v\f]/.test(c)) {
1881
+ if (value !== '') pendingSpace += c;
1882
+ continue
1883
+ }
1884
+ if (!inQuotes && (c === '#' || c === ';')) break
1885
+ value += pendingSpace;
1886
+ pendingSpace = '';
1887
+ if (c === '\\' && ESCAPED_CHARS.has(rawValue[i + 1])) {
1888
+ value += ESCAPED_CHARS.get(rawValue[++i]);
1889
+ } else if (c === '"') {
1890
+ inQuotes = !inQuotes;
1891
+ } else {
1892
+ value += c;
1893
+ }
1875
1894
  }
1876
- return valueWithoutComment
1877
- };
1878
-
1879
- const hasOddNumberOfQuotes = text => {
1880
- const numberOfQuotes = (text.match(/(?:^|[^\\])"/g) || []).length;
1881
- return numberOfQuotes % 2 !== 0
1895
+ return value
1882
1896
  };
1883
1897
 
1884
- const removeQuotes = text => {
1885
- return text.split('').reduce((newText, c, idx, text) => {
1886
- const isQuote = c === '"' && text[idx - 1] !== '\\';
1887
- const isEscapeForQuote = c === '\\' && text[idx + 1] === '"';
1888
- if (isQuote || isEscapeForQuote) {
1889
- return newText
1890
- }
1891
- return newText + c
1892
- }, '')
1898
+ // This follows write_pair in config.c of canonical git.
1899
+ const serializeValue = value => {
1900
+ if (typeof value !== 'string') return value
1901
+ const quote =
1902
+ value.startsWith(' ') || value.endsWith(' ') || /[#;]/.test(value)
1903
+ ? '"'
1904
+ : '';
1905
+ const escaped = value.replace(/[\\"\n\t]/g, c => {
1906
+ if (c === '\n') return '\\n'
1907
+ if (c === '\t') return '\\t'
1908
+ return `\\${c}`
1909
+ });
1910
+ return `${quote}${escaped}${quote}`
1893
1911
  };
1894
1912
 
1895
1913
  const lower = text => {
@@ -2061,11 +2079,7 @@ class GitConfig {
2061
2079
  return line
2062
2080
  }
2063
2081
  if (name != null && value != null) {
2064
- if (typeof value === 'string' && /[#;]/.test(value)) {
2065
- // A `#` or `;` symbol denotes a comment, so we have to wrap it in double quotes
2066
- return `\t${name} = "${value}"`
2067
- }
2068
- return `\t${name} = ${value}`
2082
+ return `\t${name} = ${serializeValue(value)}`
2069
2083
  }
2070
2084
  if (subsection != null) {
2071
2085
  return `[${section} "${subsection}"]`
@@ -10115,8 +10129,8 @@ function filterCapabilities(server, client) {
10115
10129
 
10116
10130
  const pkg = {
10117
10131
  name: 'isomorphic-git',
10118
- version: '1.44.3',
10119
- agent: 'git/isomorphic-git@1.44.3',
10132
+ version: '1.44.5',
10133
+ agent: 'git/isomorphic-git@1.44.5',
10120
10134
  };
10121
10135
 
10122
10136
  class FIFO {
package/index.js CHANGED
@@ -1816,9 +1816,11 @@ const schema = {
1816
1816
  // section is alphanumeric (ASCII) with - and .
1817
1817
  // section is case insensitive
1818
1818
  // subsection is optional
1819
- // subsection is specified after section and one or more spaces
1820
- // subsection is specified between double quotes
1821
- const SECTION_LINE_REGEX = /^\[([A-Za-z0-9-.]+)(?: "(.*)")?\]$/;
1819
+ // subsection is specified after section and one or more spaces or tabs
1820
+ // subsection is specified between double quotes, where \ escapes the next character
1821
+ // a comment can follow the section header
1822
+ const SECTION_LINE_REGEX =
1823
+ /^\[([A-Za-z0-9-.]+)(?:[ \t]+"((?:[^"\\]|\\.)*)")?\][ \t]*(?:[#;].*)?$/;
1822
1824
  const SECTION_REGEX = /^[A-Za-z0-9-.]+$/;
1823
1825
 
1824
1826
  // variable lines contain a name, and equal sign and then a value
@@ -1830,14 +1832,12 @@ const SECTION_REGEX = /^[A-Za-z0-9-.]+$/;
1830
1832
  const VARIABLE_LINE_REGEX = /^([A-Za-z][A-Za-z0-9-]*)(?:\s*=\s*(.*))?$/;
1831
1833
  const VARIABLE_NAME_REGEX = /^[A-Za-z][A-Za-z0-9-]*$/;
1832
1834
 
1833
- // Comments start with either # or ; and extend to the end of line
1834
- const VARIABLE_VALUE_COMMENT_REGEX = /^(.*?)( *[#;].*)$/;
1835
-
1836
1835
  const extractSectionLine = line => {
1837
1836
  const matches = SECTION_LINE_REGEX.exec(line);
1838
1837
  if (matches != null) {
1839
1838
  const [section, subsection] = matches.slice(1);
1840
- return [section, subsection]
1839
+ // Like canonical git, drop the backslash of an escaped character
1840
+ return [section, subsection && subsection.replace(/\\(.)/g, '$1')]
1841
1841
  }
1842
1842
  return null
1843
1843
  };
@@ -1846,43 +1846,61 @@ const extractVariableLine = line => {
1846
1846
  const matches = VARIABLE_LINE_REGEX.exec(line);
1847
1847
  if (matches != null) {
1848
1848
  const [name, rawValue = 'true'] = matches.slice(1);
1849
- const valueWithoutComments = removeComments(rawValue);
1850
- const valueWithoutQuotes = removeQuotes(valueWithoutComments);
1851
- return [name, valueWithoutQuotes]
1849
+ return [name, parseValue(rawValue)]
1852
1850
  }
1853
1851
  return null
1854
1852
  };
1855
1853
 
1856
- const removeComments = rawValue => {
1857
- const commentMatches = VARIABLE_VALUE_COMMENT_REGEX.exec(rawValue);
1858
- if (commentMatches == null) {
1859
- return rawValue
1860
- }
1861
- const [valueWithoutComment, comment] = commentMatches.slice(1);
1862
- // if odd number of quotes before and after comment => comment is escaped
1863
- if (
1864
- hasOddNumberOfQuotes(valueWithoutComment) &&
1865
- hasOddNumberOfQuotes(comment)
1866
- ) {
1867
- return `${valueWithoutComment}${comment}`
1854
+ const ESCAPED_CHARS = new Map([
1855
+ ['t', '\t'],
1856
+ ['b', '\b'],
1857
+ ['n', '\n'],
1858
+ ['\\', '\\'],
1859
+ ['"', '"'],
1860
+ ]);
1861
+
1862
+ // This follows parse_value in config.c of canonical git: double quotes are
1863
+ // removed, # and ; outside of quotes start a comment, whitespace outside of
1864
+ // quotes is kept between words but trimmed at the end, and \t, \b, \n, \\ and
1865
+ // \" are unescaped. Canonical git rejects any other escape sequence, here the
1866
+ // backslash is kept as is.
1867
+ const parseValue = rawValue => {
1868
+ let value = '';
1869
+ let pendingSpace = '';
1870
+ let inQuotes = false;
1871
+ for (let i = 0; i < rawValue.length; i++) {
1872
+ const c = rawValue[i];
1873
+ if (!inQuotes && /[ \t\r\v\f]/.test(c)) {
1874
+ if (value !== '') pendingSpace += c;
1875
+ continue
1876
+ }
1877
+ if (!inQuotes && (c === '#' || c === ';')) break
1878
+ value += pendingSpace;
1879
+ pendingSpace = '';
1880
+ if (c === '\\' && ESCAPED_CHARS.has(rawValue[i + 1])) {
1881
+ value += ESCAPED_CHARS.get(rawValue[++i]);
1882
+ } else if (c === '"') {
1883
+ inQuotes = !inQuotes;
1884
+ } else {
1885
+ value += c;
1886
+ }
1868
1887
  }
1869
- return valueWithoutComment
1870
- };
1871
-
1872
- const hasOddNumberOfQuotes = text => {
1873
- const numberOfQuotes = (text.match(/(?:^|[^\\])"/g) || []).length;
1874
- return numberOfQuotes % 2 !== 0
1888
+ return value
1875
1889
  };
1876
1890
 
1877
- const removeQuotes = text => {
1878
- return text.split('').reduce((newText, c, idx, text) => {
1879
- const isQuote = c === '"' && text[idx - 1] !== '\\';
1880
- const isEscapeForQuote = c === '\\' && text[idx + 1] === '"';
1881
- if (isQuote || isEscapeForQuote) {
1882
- return newText
1883
- }
1884
- return newText + c
1885
- }, '')
1891
+ // This follows write_pair in config.c of canonical git.
1892
+ const serializeValue = value => {
1893
+ if (typeof value !== 'string') return value
1894
+ const quote =
1895
+ value.startsWith(' ') || value.endsWith(' ') || /[#;]/.test(value)
1896
+ ? '"'
1897
+ : '';
1898
+ const escaped = value.replace(/[\\"\n\t]/g, c => {
1899
+ if (c === '\n') return '\\n'
1900
+ if (c === '\t') return '\\t'
1901
+ return `\\${c}`
1902
+ });
1903
+ return `${quote}${escaped}${quote}`
1886
1904
  };
1887
1905
 
1888
1906
  const lower = text => {
@@ -2054,11 +2072,7 @@ class GitConfig {
2054
2072
  return line
2055
2073
  }
2056
2074
  if (name != null && value != null) {
2057
- if (typeof value === 'string' && /[#;]/.test(value)) {
2058
- // A `#` or `;` symbol denotes a comment, so we have to wrap it in double quotes
2059
- return `\t${name} = "${value}"`
2060
- }
2061
- return `\t${name} = ${value}`
2075
+ return `\t${name} = ${serializeValue(value)}`
2062
2076
  }
2063
2077
  if (subsection != null) {
2064
2078
  return `[${section} "${subsection}"]`
@@ -10102,8 +10116,8 @@ function filterCapabilities(server, client) {
10102
10116
 
10103
10117
  const pkg = {
10104
10118
  name: 'isomorphic-git',
10105
- version: '1.44.3',
10106
- agent: 'git/isomorphic-git@1.44.3',
10119
+ version: '1.44.5',
10120
+ agent: 'git/isomorphic-git@1.44.5',
10107
10121
  };
10108
10122
 
10109
10123
  class FIFO {