Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(parser-adapter-yaml-1-2): incorrect quote scalars trimming #3792

Merged
merged 4 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/apidom-ast/src/yaml/schemas/canonical-format.ts
Expand Up @@ -128,11 +128,11 @@ export const formatFlowPlain = pipe(
export const formatFlowSingleQuoted = pipe(
normalizeLineBreaks,
trim,
removeQuotes("'"),
collapseLineBreakToSpace,
split('\n'),
map(trimStart),
join('\n'),
removeQuotes("'"),
);

/**
Expand All @@ -142,13 +142,13 @@ export const formatFlowSingleQuoted = pipe(
export const formatFlowDoubleQuoted = pipe(
normalizeLineBreaks,
trim,
removeQuotes('"'),
preventLineBreakCollapseToSpace,
collapseLineBreakToSpace,
unraw,
split('\n'),
map(trimStart),
join('\n'),
removeQuotes('"'),
);

/**
Expand Down
Expand Up @@ -531,7 +531,7 @@ exports[`refractor plugins normalize-operation-ids given Operation Object with o
},
"originalOperationId": {
"element": "string",
"content": ""
"content": " "
}
},
"content": [
Expand Down Expand Up @@ -568,7 +568,7 @@ exports[`refractor plugins normalize-operation-ids given Operation Object with o
},
"value": {
"element": "string",
"content": ""
"content": " "
}
}
}
Expand Down
29 changes: 28 additions & 1 deletion packages/apidom-parser-adapter-yaml-1-2/test/adapter-browser.ts
@@ -1,7 +1,13 @@
import fs from 'node:fs';
import path from 'node:path';
import { assert, expect } from 'chai';
import { toValue, isObjectElement, isParseResultElement, sexprs } from '@swagger-api/apidom-core';
import {
toValue,
isObjectElement,
isParseResultElement,
sexprs,
isStringElement,
} from '@swagger-api/apidom-core';

import * as adapter from '../src/adapter-browser';

Expand Down Expand Up @@ -126,4 +132,25 @@ describe('adapter-browser', function () {
assert.strictEqual(toValue(parseResult.errors.get(0)), '(Error YAML syntax error)');
});
});

context('given an alias', function () {
specify('should analyze alias as string', async function () {
const result = await adapter.parse('*alias');
assert.isTrue(isStringElement(result.result));
});
});

context('given single-quote scalar containing only space characters', function () {
specify('should parse all space characters', async function () {
const result = await adapter.parse("' '");
assert.strictEqual(result.toValue()[0], ' ');
});
});

context('given double-quote scalar containing only space characters', function () {
specify('should parse all space characters', async function () {
const result = await adapter.parse('" "');
assert.strictEqual(result.toValue()[0], ' ');
});
});
});
Expand Up @@ -2,7 +2,13 @@ import fs from 'node:fs';
import path from 'node:path';
import { assert, expect } from 'chai';
import { YamlTagError } from '@swagger-api/apidom-ast';
import { toValue, isObjectElement, isParseResultElement, sexprs } from '@swagger-api/apidom-core';
import {
toValue,
isObjectElement,
isParseResultElement,
sexprs,
isStringElement,
} from '@swagger-api/apidom-core';

import * as adapter from '../../src/adapter-node';

Expand Down Expand Up @@ -155,4 +161,25 @@ describe('adapter-node', function () {
}
});
});

context('given an alias', function () {
specify('should analyze alias as string', async function () {
const result = await adapter.parse('*alias');
assert.isTrue(isStringElement(result.result));
});
});

context('given single-quote scalar containing only space characters', function () {
specify('should parse all space characters', async function () {
const result = await adapter.parse("' '");
assert.strictEqual(result.toValue()[0], ' ');
});
});

context('given double-quote scalar containing only space characters', function () {
specify('should parse all space characters', async function () {
const result = await adapter.parse('" "');
assert.strictEqual(result.toValue()[0], ' ');
});
});
});

This file was deleted.