Skip to content

Commit cab635e

Browse files
authored
fix: panic when check for an identity mapping (#118)
1 parent 4859f87 commit cab635e

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/helpers.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,8 @@ pub fn stream_chunks_of_combined_source_map<'a>(
743743
});
744744
if let Some(original_chunk) = original_chunk {
745745
if original_chunk.len() <= inner_chunk.len()
746-
&& &inner_chunk[..original_chunk.len()] == original_chunk
746+
&& inner_chunk.get(..original_chunk.len())
747+
== Some(original_chunk)
747748
{
748749
inner_original_column += location_in_chunk;
749750
inner_name_index = -1;

src/source_map_source.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,4 +693,45 @@ mod tests {
693693
.unwrap()
694694
);
695695
}
696+
697+
#[test]
698+
fn should_not_panic_when_check_for_an_identity_mapping() {
699+
let source = SourceMapSource::new(SourceMapSourceOptions {
700+
value: "hello world",
701+
name: "hello.txt",
702+
source_map: SourceMap::from_json(
703+
r#"{
704+
"version": 3,
705+
"sources": ["hello.txt"],
706+
"mappings": "AAAA,MAAG"
707+
}"#,
708+
)
709+
.unwrap(),
710+
original_source: Some("你好 世界".to_string()),
711+
inner_source_map: Some(
712+
SourceMap::from_json(
713+
r#"{
714+
"version": 3,
715+
"sources": ["hello world.txt"],
716+
"mappings": "AAAA,EAAE",
717+
"sourcesContent": ["你好✋世界"]
718+
}"#,
719+
)
720+
.unwrap(),
721+
),
722+
remove_original_source: false,
723+
});
724+
assert_eq!(
725+
source.map(&MapOptions::default()).unwrap(),
726+
SourceMap::from_json(
727+
r#"{
728+
"version": 3,
729+
"mappings": "AAAA,MAAE",
730+
"sources": ["hello world.txt"],
731+
"sourcesContent": ["你好✋世界"]
732+
}"#
733+
)
734+
.unwrap()
735+
);
736+
}
696737
}

0 commit comments

Comments
 (0)