fix(anatomy): R5.4 authored backticks refused, underscores paired across code spans refused; sweep cites probe_ref and probe_ref_
This commit is contained in:
1 parent
aff3a96d55
commit
bc5d0ad038
7 files changed
+91
-29
No files matched your search
@@ -13,6 +13,7 @@ use super::stats::{DocumentStats, stat_rows};
|
||||
use super::targets::fail;
|
||||
use crate::curation::PipelineError;
|
||||
use crate::curation::markdown::{Cell, code, table};
|
||||
use crate::curation::report_guard::assert_authored;
|
||||
use crate::json::to_js_compact;
|
||||
|
||||
/// The longest value text a table cell shows, in UTF-16 units (`text.length`).
|
||||
@@ -51,6 +52,11 @@ pub fn compact_value(value: &Value) -> Result<String, PipelineError> {
|
||||
))
|
||||
}
|
||||
|
||||
fn authored(text: String) -> Result<String, PipelineError> {
|
||||
assert_authored(&text)?;
|
||||
Ok(text)
|
||||
}
|
||||
|
||||
/// `recordSubject`: the target, with its field when there is one.
|
||||
pub fn record_subject(record: &ChangeRecord) -> String {
|
||||
match &record.field {
|
||||
@@ -60,6 +66,9 @@ pub fn record_subject(record: &ChangeRecord) -> String {
|
||||
}
|
||||
|
||||
fn record_row(record: &ChangeRecord) -> Result<Vec<Cell>, PipelineError> {
|
||||
// Authored texts reach the cells raw: no backtick (code spans are the generator's).
|
||||
assert_authored(&record.change.title.fr)?;
|
||||
assert_authored(&record.change.rationale)?;
|
||||
let change = &record.change;
|
||||
let references: Vec<String> = change
|
||||
.reference_ids
|
||||
@@ -79,8 +88,8 @@ fn record_row(record: &ChangeRecord) -> Result<Vec<Cell>, PipelineError> {
|
||||
Ok(vec![
|
||||
Cell::from(format!("{} {}", code(Some(&change.id)), change.title.fr)),
|
||||
Cell::from(code(Some(&record_subject(record)))),
|
||||
Cell::from(compact_value(&record.before)?),
|
||||
Cell::from(compact_value(&record.after)?),
|
||||
Cell::from(authored(compact_value(&record.before)?)?),
|
||||
Cell::from(authored(compact_value(&record.after)?)?),
|
||||
Cell::from(kind_label(change.kind)),
|
||||
Cell::from(change.rationale.as_str()),
|
||||
Cell::from(references),
|
||||
|
||||
@@ -18,6 +18,7 @@ use super::targets::{Step, TargetKind, all_findings, at, top_collection_path, zo
|
||||
use crate::curation::PipelineError;
|
||||
use crate::curation::legacy::types::Anomaly;
|
||||
use crate::curation::markdown::{Cell, code, table};
|
||||
use crate::curation::report_guard::assert_authored;
|
||||
use crate::curation::text::utf16_cmp;
|
||||
|
||||
pub struct ReviewReportInput<'a> {
|
||||
@@ -361,7 +362,7 @@ fn assert_single_line(text: &str) -> Result<(), PipelineError> {
|
||||
if text.chars().any(char::is_control) {
|
||||
return Err(PipelineError::UnsupportedMarkdown(text.to_owned()));
|
||||
}
|
||||
Ok(())
|
||||
assert_authored(text)
|
||||
}
|
||||
|
||||
fn assert_list_items_single_line(input: &ReviewReportInput<'_>) -> Result<(), PipelineError> {
|
||||
|
||||
@@ -3,15 +3,18 @@
|
||||
//! rewrites Markdown in authored text (escapes, emphasis, whitespace, links). Rather than
|
||||
//! chase every such rewrite, the guard admits an allowlist proven identical by the TypeScript
|
||||
//! sweep (`oracles/r5/markdown-sweep.json`, hand-picked and seeded random probes) and by the
|
||||
//! equine reports, and refuses everything else with `UnsupportedMarkdown`: a report is either
|
||||
//! byte for byte the TypeScript's or not written.
|
||||
//! equine reports, and refuses everything else with `UnsupportedMarkdown`. Within what the probes
|
||||
//! cover, a report is either byte for byte the TypeScript's or not written; a combination of
|
||||
//! admitted characters no rule names and no probe covers could still differ (RUST.md §11.15).
|
||||
//!
|
||||
//! Admitted outside code spans: letters and digits, single spaces (none at a line end), the
|
||||
//! punctuation of `PUNCTUATION`, an underscore between two ASCII letters or digits and not
|
||||
//! glued to a URL, a backslash before `"` or `|` (a JSON quote, the cell escape), `**word**`
|
||||
//! (one run of letters between spaces or line edges, the import report's form), no inline
|
||||
//! construct (`rewritten_construct`). Inside code spans (the generated ids and targets):
|
||||
//! anything but a carriage return or a tab, never empty, no outer space.
|
||||
//! anything but a carriage return or a tab, never empty, no outer space; an authored text holds
|
||||
//! no backtick (`assert_authored`), and a plain underscore is never followed by another one on its
|
||||
//! line.
|
||||
|
||||
use super::PipelineError;
|
||||
use super::markdown::{format_markdown, split_row};
|
||||
@@ -171,15 +174,47 @@ fn guard_text(text: &str) -> bool {
|
||||
if parts.len().is_multiple_of(2) || text.contains(['\r', '\t']) || text.ends_with(' ') {
|
||||
return false;
|
||||
}
|
||||
parts.iter().enumerate().all(|(index, part)| {
|
||||
let admitted = parts.iter().enumerate().all(|(index, part)| {
|
||||
if index % 2 == 1 {
|
||||
!part.is_empty() && !part.starts_with(' ') && !part.ends_with(' ')
|
||||
} else {
|
||||
admitted_plain(part)
|
||||
}
|
||||
});
|
||||
admitted && !underscore_pairs_later(&parts)
|
||||
}
|
||||
|
||||
/// Prettier's parser pairs a plain-text underscore with a later underscore that can close an
|
||||
/// emphasis: one inside a later code span followed by anything but an ASCII letter or digit,
|
||||
/// the span's closing backtick included (`to_do … \`ref_\`` became `to*do … \`ref*\``). A
|
||||
/// plain underscore is always between ASCII letters or digits here, so it never closes; the
|
||||
/// equine `{"min_x":60,"min_y":100,…}` stays admitted.
|
||||
fn underscore_pairs_later(parts: &[&str]) -> bool {
|
||||
let closes = |code: &str| {
|
||||
let chars: Vec<char> = code.chars().collect();
|
||||
(0..chars.len())
|
||||
.any(|i| chars[i] == '_' && chars.get(i + 1).is_none_or(|c| !c.is_ascii_alphanumeric()))
|
||||
};
|
||||
parts.iter().enumerate().any(|(index, part)| {
|
||||
index % 2 == 0
|
||||
&& part.contains('_')
|
||||
&& parts[index + 1..]
|
||||
.iter()
|
||||
.enumerate()
|
||||
.any(|(offset, later)| (index + 1 + offset) % 2 == 1 && closes(later))
|
||||
})
|
||||
}
|
||||
|
||||
/// An authored text the reports write must carry no backtick: code spans come from the
|
||||
/// generator alone (ids, targets, field names), never from an author (a backtick there let a
|
||||
/// link or a URL run into a code span, Prettier rewriting both).
|
||||
pub fn assert_authored(text: &str) -> Result<(), PipelineError> {
|
||||
if text.contains('`') {
|
||||
return Err(refuse(text));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Refuses a raw report line outside the allowlist, cell by cell in a table row.
|
||||
fn guard_line(line: &str) -> Result<(), PipelineError> {
|
||||
let admitted = if line.starts_with('|') {
|
||||
|
||||
Reference in new issue
Block a user