<commit_before>package net.nemerosa.ontrack.ui.controller;

import net.nemerosa.ontrack.common.RunProfile;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder;

import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;

import static java.lang.String.format;

@Component
@Profile({RunProfile.UNIT_TEST})
public class MockURIBuilder implements URIBuilder {
    @Override
    public URI build(Object invocationInfo) {
        MvcUriComponentsBuilder.MethodInvocationInfo info = (MvcUriComponentsBuilder.MethodInvocationInfo) invocationInfo;
        try {
            return URI.create(
                    format(
                            "urn:test:%s#%s:%s",
                            info.getControllerMethod().getDeclaringClass().getName(),
                            info.getControllerMethod().getName(),
                            URLEncoder.encode(
                                    StringUtils.join(info.getArgumentValues(), ","),
                                    "UTF-8"
                            )
                    )
            );
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("Cannot encode URI parameter", e);
        }
    }
}<commit_msg>#172 Correction of encoding<commit_after>package net.nemerosa.ontrack.ui.controller;

import net.nemerosa.ontrack.common.RunProfile;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder;

import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;

import static java.lang.String.format;

@Component
@Profile({RunProfile.UNIT_TEST})
public class MockURIBuilder implements URIBuilder {
    @Override
    public URI build(Object invocationInfo) {
        MvcUriComponentsBuilder.MethodInvocationInfo info = (MvcUriComponentsBuilder.MethodInvocationInfo) invocationInfo;
        return URI.create(
                format(
                        "urn:test:%s#%s:%s",
                        info.getControllerMethod().getDeclaringClass().getName(),
                        info.getControllerMethod().getName(),
                        Arrays.asList(info.getArgumentValues()).stream()
                                .map(o -> Objects.toString(o, ""))
                                .map(this::encode)
                                .collect(Collectors.joining(","))
                )
        );
    }

    private String encode(String s) {
        try {
            return URLEncoder.encode(s, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("Cannot encode URI parameter", e);
        }
    }
}
{'fraction_non_alphanumeric': 0.09735973597359736, 'fraction_numerical': 0.0019801980198019802, 'mean_word_length': 2.2945652173913045, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6820610', 'n_tokens_mistral': 776, 'n_tokens_neox': 764, 'n_words': 130}