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 support of special characters in service names #1045

Merged
merged 3 commits into from
Feb 8, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

All changes that impact users of this module are documented in this file, in the [Common Changelog](https://common-changelog.org) format with some additional specifications defined in the CONTRIBUTING file. This codebase adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## Unreleased [patch]

### Fixed

_Full changeset and discussions: [#1045](https://github.com/OpenTermsArchive/engine/pull/1045)._

> Development of this release was supported by the [French Ministry for Foreign Affairs](https://www.diplomatie.gouv.fr/fr/politique-etrangere-de-la-france/diplomatie-numerique/) through its ministerial [State Startups incubator](https://beta.gouv.fr/startups/open-terms-archive.html) under the aegis of the Ambassador for Digital Affairs.

- Fix support of special character in service names

## 0.34.1 - 2023-12-19

Expand Down
14 changes: 7 additions & 7 deletions src/archivist/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function resetGitRepositories() {
describe('Archivist', function () {
this.timeout(10000);

const SERVICE_A_ID = 'service_A';
const SERVICE_A_ID = 'service·A';
const SERVICE_A_TYPE = 'Terms of Service';
const SERVICE_A_EXPECTED_SNAPSHOT_FILE_PATH = `${SNAPSHOTS_PATH}/${SERVICE_A_ID}/${SERVICE_A_TYPE}.html`;
const SERVICE_A_EXPECTED_VERSION_FILE_PATH = `${VERSIONS_PATH}/${SERVICE_A_ID}/${SERVICE_A_TYPE}.md`;
Expand All @@ -49,7 +49,7 @@ describe('Archivist', function () {
let serviceBSnapshotExpectedContent;
let serviceBVersionExpectedContent;

const services = [ 'service_A', 'Service B!' ];
const services = [ 'service·A', 'Service B!' ];

before(async () => {
gitVersion = new Git({
Expand All @@ -61,8 +61,8 @@ describe('Archivist', function () {
});
await gitVersion.initialize();

serviceASnapshotExpectedContent = await fs.readFile(path.resolve(ROOT_PATH, 'test/fixtures/service_A_terms_snapshot.html'), { encoding: 'utf8' });
serviceAVersionExpectedContent = await fs.readFile(path.resolve(ROOT_PATH, 'test/fixtures/service_A_terms.md'), { encoding: 'utf8' });
serviceASnapshotExpectedContent = await fs.readFile(path.resolve(ROOT_PATH, 'test/fixtures/service·A_terms_snapshot.html'), { encoding: 'utf8' });
serviceAVersionExpectedContent = await fs.readFile(path.resolve(ROOT_PATH, 'test/fixtures/service·A_terms.md'), { encoding: 'utf8' });
serviceBSnapshotExpectedContent = await fs.readFile(path.resolve(ROOT_PATH, 'test/fixtures/terms.pdf'));
serviceBVersionExpectedContent = await fs.readFile(path.resolve(ROOT_PATH, 'test/fixtures/termsFromPDF.md'), { encoding: 'utf8' });
});
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('Archivist', function () {

app.services[SERVICE_A_ID].getTerms({ type: SERVICE_A_TYPE }).sourceDocuments[0].contentSelectors = 'h1';

await app.track({ services: [ 'service_A', 'Service B!' ], extractOnly: true });
await app.track({ services: [ 'service·A', 'Service B!' ], extractOnly: true });

const [reExtractedVersionCommit] = await gitVersion.log({ file: SERVICE_A_EXPECTED_VERSION_FILE_PATH });

Expand Down Expand Up @@ -282,7 +282,7 @@ describe('Archivist', function () {
let snapshot;

before(async () => {
terms = app.services.service_A.getTerms({ type: SERVICE_A_TYPE });
terms = app.services.service·A.getTerms({ type: SERVICE_A_TYPE });
terms.fetchDate = FETCH_DATE;
terms.sourceDocuments.forEach(async sourceDocument => {
sourceDocument.content = serviceASnapshotExpectedContent;
Expand Down Expand Up @@ -364,7 +364,7 @@ describe('Archivist', function () {
let version;

before(async () => {
terms = app.services.service_A.getTerms({ type: SERVICE_A_TYPE });
terms = app.services.service·A.getTerms({ type: SERVICE_A_TYPE });
terms.fetchDate = FETCH_DATE;
terms.sourceDocuments.forEach(async sourceDocument => {
sourceDocument.content = serviceASnapshotExpectedContent;
Expand Down
3 changes: 2 additions & 1 deletion src/archivist/recorder/repositories/git/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export default class Git {
.addConfig('core.autocrlf', false)
.addConfig('push.default', 'current')
.addConfig('user.name', this.author.name)
.addConfig('user.email', this.author.email);
.addConfig('user.email', this.author.email)
.addConfig('core.quotePath', false); // disable Git's encoding of special characters in pathnames. For example, `service·A` will be encoded as `service\302\267A` without this setting, leading to issues. See https://git-scm.com/docs/git-config#Documentation/git-config.txt-corequotePath
}

async add(filePath) {
Expand Down
16 changes: 8 additions & 8 deletions src/archivist/services/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ describe('Services', () => {
result = await services.load();
});

describe('Service A', async () => {
await validateServiceWithoutHistory('service_A', expectedServices.service_A);
describe('Service·A', async () => {
await validateServiceWithoutHistory('service·A', expectedServices.service·A);
});

describe('Service B', async () => {
Expand Down Expand Up @@ -127,11 +127,11 @@ describe('Services', () => {

context('when specifying services to load', async () => {
before(async () => {
result = await services.load([ 'service_A', 'Service B!' ]);
result = await services.load([ 'service·A', 'Service B!' ]);
});

it('loads only the given services', async () => {
expect(result).to.have.all.keys('service_A', 'Service B!');
expect(result).to.have.all.keys('service·A', 'Service B!');
});
});
});
Expand Down Expand Up @@ -266,8 +266,8 @@ describe('Services', () => {
result = await services.loadWithHistory();
});

describe('Service A', async () => {
await validateServiceWithHistory('service_A', expectedServices.service_A);
describe('Service·A', async () => {
await validateServiceWithHistory('service·A', expectedServices.service·A);
});

describe('Service B', async () => {
Expand Down Expand Up @@ -296,11 +296,11 @@ describe('Services', () => {

context('when specifying services to load', async () => {
before(async () => {
result = await services.loadWithHistory([ 'service_A', 'Service B!' ]);
result = await services.loadWithHistory([ 'service·A', 'Service B!' ]);
});

it('loads only the given services', async () => {
expect(result).to.have.all.keys('service_A', 'Service B!');
expect(result).to.have.all.keys('service·A', 'Service B!');
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/services.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import serviceA from './service_A.js';
import serviceB from './service_B.js';
import serviceWithDeclarationHistory from './service_with_declaration_history.js';
import serviceWithFiltersHistory from './service_with_filters_history.js';
import serviceWithHistory from './service_with_history.js';
import serviceWithMultipleSourceDocumentsTerms from './service_with_multiple_source_documents_terms.js';
import serviceWithoutHistory from './service_without_history.js';
import serviceA from './service·A.js';

const services = {
service_with_history: serviceWithHistory,
service_without_history: serviceWithoutHistory,
service_with_filters_history: serviceWithFiltersHistory,
service_with_declaration_history: serviceWithDeclarationHistory,
service_with_multiple_source_documents_terms: serviceWithMultipleSourceDocumentsTerms,
service_A: serviceA,
service·A: serviceA,
'Service B!': serviceB,
};

Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/service_A.js → test/fixtures/service·A.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import SourceDocument from '../../src/archivist/services/sourceDocument.js';
import Terms from '../../src/archivist/services/terms.js';

const service = new Service({
id: 'service_A',
name: 'Service A',
id: 'service·A',
name: 'Service·A',
});

service.addTerms(new Terms({
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Service A",
"name": "Service·A",
"documents": {
"Terms of Service": {
"fetch": "https://www.servicea.example/tos",
Expand Down
Loading