def test_fuzzy_mapping(self): smap_view = view_from_json(indexed_sourcemap_example) # one.js assert smap_view.lookup_token(0, 20) == Token(dst_line=0, dst_col=18, src='/the/root/one.js', src_line=0, src_col=21, src_id=0, name='bar') assert smap_view.lookup_token(0, 30) == Token(dst_line=0, dst_col=28, src='/the/root/one.js', src_line=1, src_col=10, src_id=0, name='baz') assert smap_view.lookup_token(1, 12) == Token(dst_line=1, dst_col=9, src='/the/root/two.js', src_line=0, src_col=11, src_id=1, name=None)
def fetch_sourcemap(url, project=None, release=None, allow_scraping=True): if is_data_uri(url): try: body = base64.b64decode(url[BASE64_PREAMBLE_LENGTH:] + ( b'=' * (-(len(url) - BASE64_PREAMBLE_LENGTH) % 4))) except TypeError as e: raise UnparseableSourcemap({ 'url': '<base64>', 'reason': e.message, }) else: result = fetch_file(url, project=project, release=release, allow_scraping=allow_scraping) body = result.body # This is just a quick sanity check, but doesn't guarantee if not is_utf8(result.encoding): error = { 'type': EventError.JS_INVALID_SOURCE_ENCODING, 'value': 'utf8', 'url': expose_url(url), } raise CannotFetchSource(error) try: return view_from_json(body) except Exception as exc: # This is in debug because the product shows an error already. logger.debug(six.text_type(exc), exc_info=True) raise UnparseableSourcemap({ 'url': expose_url(url), })
def test_indexed_inline(self): smap_view = view_from_json(indexed_sourcemap_example) assert smap_view.get_source_contents(0) == ( ' ONE.foo = function (bar) {\n' + ' return baz(bar);\n' + ' };') assert smap_view.get_source_contents(1) == ( ' TWO.inc = function (n) {\n' + ' return n + 1;\n' + ' };')
def fetch_sourcemap(url, project=None, release=None, dist=None, allow_scraping=True): if is_data_uri(url): try: body = base64.b64decode(url[BASE64_PREAMBLE_LENGTH:] + ( b'=' * (-(len(url) - BASE64_PREAMBLE_LENGTH) % 4))) except TypeError as e: raise UnparseableSourcemap({ 'url': '<base64>', 'reason': e.message, }) else: result = fetch_file(url, project=project, release=release, dist=dist, allow_scraping=allow_scraping) body = result.body try: return view_from_json(body) except Exception as exc: # This is in debug because the product shows an error already. logger.debug(six.text_type(exc), exc_info=True) raise UnparseableSourcemap({ 'url': http.expose_url(url), })
def fetch_sourcemap(url, project=None, release=None, allow_scraping=True): if is_data_uri(url): try: body = base64.b64decode( url[BASE64_PREAMBLE_LENGTH:] + (b'=' * (-(len(url) - BASE64_PREAMBLE_LENGTH) % 4)) ) except TypeError as e: raise UnparseableSourcemap({ 'url': '<base64>', 'reason': e.message, }) else: result = fetch_file(url, project=project, release=release, allow_scraping=allow_scraping) body = result.body # This is just a quick sanity check, but doesn't guarantee if not is_utf8(result.encoding): error = { 'type': EventError.JS_INVALID_SOURCE_ENCODING, 'value': 'utf8', 'url': expose_url(url), } raise CannotFetchSource(error) try: return view_from_json(body) except Exception as exc: # This is in debug because the product shows an error already. logger.debug(six.text_type(exc), exc_info=True) raise UnparseableSourcemap({ 'url': expose_url(url), })
def fetch_sourcemap(url, project=None, release=None, dist=None, allow_scraping=True): if is_data_uri(url): try: body = base64.b64decode( url[BASE64_PREAMBLE_LENGTH:] + (b'=' * (-(len(url) - BASE64_PREAMBLE_LENGTH) % 4)) ) except TypeError as e: raise UnparseableSourcemap({ 'url': '<base64>', 'reason': e.message, }) else: result = fetch_file(url, project=project, release=release, dist=dist, allow_scraping=allow_scraping) body = result.body try: return view_from_json(body) except Exception as exc: # This is in debug because the product shows an error already. logger.debug(six.text_type(exc), exc_info=True) raise UnparseableSourcemap({ 'url': http.expose_url(url), })
def test_fuzzy_mapping(self): smap_view = view_from_json(indexed_sourcemap_example) # one.js assert smap_view.lookup_token(0, 20) == \ Token(dst_line=0, dst_col=18, src='/the/root/one.js', src_line=0, src_col=21, src_id=0, name='bar') assert smap_view.lookup_token(0, 30) == \ Token(dst_line=0, dst_col=28, src='/the/root/one.js', src_line=1, src_col=10, src_id=0, name='baz') assert smap_view.lookup_token(1, 12) == \ Token(dst_line=1, dst_col=9, src='/the/root/two.js', src_line=0, src_col=11, src_id=1, name=None)
def test_simple(self): smap_view = view_from_json(sourcemap) result = smap_view.lookup_token(0, 56) assert result == Token(dst_line=0, dst_col=50, src='foo/file2.js', src_line=0, src_col=9, src_id=1, name='multiply') # Start of minified file (exact match first line/col tuple) result = smap_view.lookup_token(0, 0) assert result == Token(dst_line=0, dst_col=0, src='foo/file1.js', src_line=0, src_col=0, src_id=0, name=None) # Last character in mapping result = smap_view.lookup_token(0, 36) assert result == Token(dst_line=0, dst_col=30, src='foo/file1.js', src_line=2, src_col=1, src_id=0, name=None) # First character in mapping (exact match line/col tuple) result = smap_view.lookup_token(0, 37) assert result == Token(dst_line=0, dst_col=37, src='foo/file1.js', src_line=2, src_col=8, src_id=0, name='a') # End of minified file (character *beyond* last line/col tuple) result = smap_view.lookup_token(0, 192) assert result == Token(dst_line=0, dst_col=191, src='foo/file2.js', src_line=9, src_col=25, src_id=1, name='e')
def test_exact_mappings(self): smap_view = view_from_json(indexed_sourcemap_example) # one.js assert smap_view.lookup_token(0, 1) == Token(dst_line=0, dst_col=1, src='/the/root/one.js', src_line=0, src_col=1, src_id=0, name=None) assert smap_view.lookup_token(0, 18) == Token(dst_line=0, dst_col=18, src='/the/root/one.js', src_line=0, src_col=21, src_id=0, name='bar') assert smap_view.lookup_token(0, 28) == Token(dst_line=0, dst_col=28, src='/the/root/one.js', src_line=1, src_col=10, src_id=0, name='baz') # two.js assert smap_view.lookup_token(1, 18) == Token(dst_line=1, dst_col=18, src='/the/root/two.js', src_line=0, src_col=21, src_id=1, name='n') assert smap_view.lookup_token(1, 21) == Token(dst_line=1, dst_col=21, src='/the/root/two.js', src_line=1, src_col=3, src_id=1, name=None) assert smap_view.lookup_token(1, 21) == Token(dst_line=1, dst_col=21, src='/the/root/two.js', src_line=1, src_col=3, src_id=1, name=None)
def fetch_sourcemap(url, project=None, release=None, allow_scraping=True): if is_data_uri(url): body = base64.b64decode(url[BASE64_PREAMBLE_LENGTH:]) else: # TODO(mattrobenolt): this is returning unicodes, and there's no # reason we need to do this. We operate on this payload as bytes. result = fetch_file(url, project=project, release=release, allow_scraping=allow_scraping) body = result.body try: return view_from_json(body) except Exception as exc: # This is in debug because the product shows an error already. logger.debug(six.text_type(exc), exc_info=True) raise UnparseableSourcemap({ 'url': expose_url(url), })
def test_exact_mappings(self): smap_view = view_from_json(indexed_sourcemap_example) # one.js assert smap_view.lookup_token(0, 1) == \ Token(dst_line=0, dst_col=1, src='/the/root/one.js', src_line=0, src_col=1, src_id=0, name=None) assert smap_view.lookup_token(0, 18) == \ Token(dst_line=0, dst_col=18, src='/the/root/one.js', src_line=0, src_col=21, src_id=0, name='bar') assert smap_view.lookup_token(0, 28) == \ Token(dst_line=0, dst_col=28, src='/the/root/one.js', src_line=1, src_col=10, src_id=0, name='baz') # two.js assert smap_view.lookup_token(1, 18) == \ Token(dst_line=1, dst_col=18, src='/the/root/two.js', src_line=0, src_col=21, src_id=1, name='n') assert smap_view.lookup_token(1, 21) == \ Token(dst_line=1, dst_col=21, src='/the/root/two.js', src_line=1, src_col=3, src_id=1, name=None) assert smap_view.lookup_token(1, 21) == \ Token(dst_line=1, dst_col=21, src='/the/root/two.js', src_line=1, src_col=3, src_id=1, name=None)
def test_basic(self): index = view_from_json(sourcemap) assert list(index) == [ Token(dst_line=0, dst_col=0, src='foo/file1.js', src_line=0, src_col=0, src_id=0, name=None), Token(dst_line=0, dst_col=8, src='foo/file1.js', src_line=0, src_col=9, src_id=0, name='add'), Token(dst_line=0, dst_col=13, src='foo/file1.js', src_line=0, src_col=13, src_id=0, name='a'), Token(dst_line=0, dst_col=15, src='foo/file1.js', src_line=0, src_col=16, src_id=0, name='b'), Token(dst_line=0, dst_col=18, src='foo/file1.js', src_line=1, src_col=1, src_id=0, name=None), Token(dst_line=0, dst_col=30, src='foo/file1.js', src_line=2, src_col=1, src_id=0, name=None), Token(dst_line=0, dst_col=37, src='foo/file1.js', src_line=2, src_col=8, src_id=0, name='a'), Token(dst_line=0, dst_col=40, src='foo/file1.js', src_line=2, src_col=12, src_id=0, name='b'), Token(dst_line=0, dst_col=42, src='foo/file2.js', src_line=0, src_col=0, src_id=1, name=None), Token(dst_line=0, dst_col=50, src='foo/file2.js', src_line=0, src_col=9, src_id=1, name='multiply'), Token(dst_line=0, dst_col=60, src='foo/file2.js', src_line=0, src_col=18, src_id=1, name='a'), Token(dst_line=0, dst_col=62, src='foo/file2.js', src_line=0, src_col=21, src_id=1, name='b'), Token(dst_line=0, dst_col=65, src='foo/file2.js', src_line=1, src_col=1, src_id=1, name=None), Token(dst_line=0, dst_col=77, src='foo/file2.js', src_line=2, src_col=1, src_id=1, name=None), Token(dst_line=0, dst_col=84, src='foo/file2.js', src_line=2, src_col=8, src_id=1, name='a'), Token(dst_line=0, dst_col=87, src='foo/file2.js', src_line=2, src_col=12, src_id=1, name='b'), Token(dst_line=0, dst_col=89, src='foo/file2.js', src_line=4, src_col=0, src_id=1, name=None), Token(dst_line=0, dst_col=97, src='foo/file2.js', src_line=4, src_col=9, src_id=1, name='divide'), Token(dst_line=0, dst_col=105, src='foo/file2.js', src_line=4, src_col=16, src_id=1, name='a'), Token(dst_line=0, dst_col=107, src='foo/file2.js', src_line=4, src_col=19, src_id=1, name='b'), Token(dst_line=0, dst_col=110, src='foo/file2.js', src_line=5, src_col=1, src_id=1, name=None), Token(dst_line=0, dst_col=122, src='foo/file2.js', src_line=6, src_col=1, src_id=1, name=None), Token(dst_line=0, dst_col=127, src='foo/file2.js', src_line=7, src_col=2, src_id=1, name=None), Token(dst_line=0, dst_col=133, src='foo/file2.js', src_line=7, src_col=9, src_id=1, name='multiply'), Token(dst_line=0, dst_col=143, src='foo/file2.js', src_line=7, src_col=18, src_id=1, name='add'), Token(dst_line=0, dst_col=147, src='foo/file2.js', src_line=7, src_col=22, src_id=1, name='a'), Token(dst_line=0, dst_col=149, src='foo/file2.js', src_line=7, src_col=25, src_id=1, name='b'), Token(dst_line=0, dst_col=152, src='foo/file2.js', src_line=7, src_col=29, src_id=1, name='a'), Token(dst_line=0, dst_col=154, src='foo/file2.js', src_line=7, src_col=32, src_id=1, name='b'), Token(dst_line=0, dst_col=157, src='foo/file2.js', src_line=7, src_col=37, src_id=1, name='c'), Token(dst_line=0, dst_col=159, src='foo/file2.js', src_line=8, src_col=3, src_id=1, name=None), Token(dst_line=0, dst_col=165, src='foo/file2.js', src_line=8, src_col=10, src_id=1, name='e'), Token(dst_line=0, dst_col=168, src='foo/file2.js', src_line=9, src_col=2, src_id=1, name='Raven'), Token(dst_line=0, dst_col=174, src='foo/file2.js', src_line=9, src_col=8, src_id=1, name='captureException'), Token(dst_line=0, dst_col=191, src='foo/file2.js', src_line=9, src_col=25, src_id=1, name='e'), ]
def test_basic(self): smap_view = view_from_json(sourcemap) assert list(smap_view.iter_sources()) == [ (0, 'foo/file1.js'), (1, 'foo/file2.js'), ]
def test_no_inline(self): # basic sourcemap fixture has no inlined sources, so expect None smap_view = view_from_json(sourcemap) source = smap_view.get_source_contents(0) assert source is None