Skip to content
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
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,21 @@ Note that for this major version, almost every change listed below is breaking.
- Comments now live on the source. `Prism::Source#comments` returns them and `Result#comments` delegates to it, so `ParseResult.new`, `LexResult.new`, and `ParseLexResult.new` no longer take a `comments` argument.
- Comment attachment now happens during parsing with the `attach_comments` option instead of afterward with `ParseResult#attach_comments!`, which was removed. `Node#comments` now returns the comments attached to the node by that option. `Location#comments`, `Location#leading_comments`, `Location#trailing_comments`, `Node#leading_comments`, `Node#trailing_comments`, and the comment fields of `Prism::Relocation` were removed.

#### C/Rust
#### C

- Most structs are now opaque (except for nodes), and many internal functions have been hidden.
- Locations are now represented using slices (pairs of 32-bit integers for start offset and length).
- Most allocations are now performed through an arena.
- You may now build side tables of comment attachments through the `attach_comments` option.
- `newline_list` was renamed to `list_offset_list`.

#### Rust

- Locations are now represented using slices (pairs of 32-bit integers for start offset and length).
- Most allocations are now performed through an arena.
- `newline_list` was renamed to `list_offset_list`.
- `Diagnostic::message` now returns `&[u8]` instead of `&str`.

#### JavaScript

- The parse method now only accepts `Uint8Array`, instead of forcing a transcoding to UTF-16.
Expand Down
11 changes: 11 additions & 0 deletions rust/ruby-prism/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,17 @@ end
assert!(stmt.as_local_variable_read_node().is_some());
}

#[test]
fn diagnostic_message_test() {
let source = b"# encoding: shift_jis\nx = <<~\x82\xA0\n";
let result = parse(source);
let error = result.errors().next().unwrap();

let message = error.message();
assert!(std::str::from_utf8(message).is_err());
assert!(message.windows(2).any(|window| window == b"\x82\xA0"));
}

#[test]
fn malformed_shebang() {
let source = "#!\x00";
Expand Down
10 changes: 5 additions & 5 deletions rust/ruby-prism/src/parse_result/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ pub struct Diagnostic<'pr> {
impl<'pr> Diagnostic<'pr> {
/// Returns the message associated with the diagnostic.
///
/// # Panics
///
/// Panics if the message is not valid UTF-8.
/// The message is in the encoding of the source, because some messages
/// quote the source directly. It is therefore not guaranteed to be valid
/// UTF-8.
#[must_use]
pub fn message(&self) -> &str {
pub fn message(&self) -> &[u8] {
unsafe {
let message = pm_diagnostic_message(self.raw);
CStr::from_ptr(message).to_str().expect("prism allows only UTF-8 for diagnostics.")
CStr::from_ptr(message).to_bytes()
}
}

Expand Down
Loading