geostyler / geostyler-qgis-parser

GeoStyler Style Parser implementation for QGIS
https://geostyler.org
BSD 2-Clause "Simplified" License
17 stars 9 forks source link

On Windows, "#writeStyle" tests fail #339

Closed pprev94 closed 2 years ago

pprev94 commented 2 years ago

On Windows :

To fix it, I suggest in function writeStyle of QGISStyleParser class

let renderOpts = { pretty: true, indent: '  ', newline: '\n' };
if ('win32' === process.platform) {
  renderOpts.newline = '\r\n'; 
}

return new Promise<WriteStyleResult<string>>(resolve => {
  try {
    const builder = new Builder({ renderOpts: renderOpts });
...

Is there a better way to do it ?

KaiVolland commented 2 years ago

Hey @pprev94. Thanks for the report.

Would be cool if we could keep this in sync with the SLD-Parser: https://github.com/geostyler/geostyler-sld-parser/blob/master/src/SldStyleParser.ts#L1303

We have an prettyOutput option over there. Could you check if this would fix it for you?

pprev94 commented 2 years ago

I've the same errors in SLD parser too prettyOutput is not enough, we need to define newline characters to '\r\n' for windows

KaiVolland commented 2 years ago

Ohh ok. Maybe there is a way to fix this issue within the testsuite instead of a change to the parser. I don't know when i'll find time to have a closer look at this.

pprev94 commented 2 years ago

May I suggest to remove the character '\r'

const qml = fs.readFileSync('./data/qmls/no_symbolizer.qml', 'utf8').replace(/\r/g, "")

Now tests run correctly

KaiVolland commented 2 years ago

I'll have a look at this later.

KaiVolland commented 2 years ago

What surprises me is that the linebreak when reading the file can be different. I thought this information would be stored in the file. Lineending should be LF (\n) for all qml files. :thinking:

KaiVolland commented 2 years ago

Lineending should be LF (\n) for all qml files.

If this is not the case for you @pprev94 . We may need to add a .gitattributes file to force LF (\n) when checking out:

https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings#example